Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 850305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:14:36+00:00 2026-05-15T07:14:36+00:00

I’m completely new to programming and I’m trying to build an autorespoder to send

  • 0

I’m completely new to programming and I’m trying to build an autorespoder to send a msg to a specific email address.

Using an if statement, I can check if there is an email from a certain address in the inbox and I can send an email, but if there are multiple emails from that address, how can I make a for loop to send an email for every email from that specific address.

I tried to do use this as a loop:

for M.search(None, 'From', address) in M.select(): 

but I get the error: “can’t assign to function call” on that line

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:14:37+00:00Added an answer on May 15, 2026 at 7:14 am

    As you claim to be new to programming, my best advice is: Always read the documentation.

    And maybe you should read a tutorial first.


    The documentation provides an example:

    import getpass, imaplib
    
    M = imaplib.IMAP4()
    M.login(getpass.getuser(), getpass.getpass())
    M.select()
    typ, data = M.search(None, 'ALL')
    for num in data[0].split():
        typ, data = M.fetch(num, '(RFC822)')
        print 'Message %s\n%s\n' % (num, data[0][3])
    M.close()
    M.logout()
    

    Have you tried?


    Regarding your code:

    When you define a for loop, it should be like:

    for x in some_data_set:
    

    x is a variable, that holds the value of one item at a time (and is accessible only in the for loop body (with one exception, but this is not important here)).

    What you are doing is not related to the imaplib module but just wrong syntax.

    Btw. .select() selects a mailbox and only returns the number of messages in the mailbox. I.e. just a scalar value, no sequence you could iterate over:

    IMAP4.select([mailbox[, readonly]])
    Select a mailbox. Returned data is the count of messages in mailbox (EXISTS response). The default mailbox is ‘INBOX’. If the readonly flag is set, modifications to the mailbox are not allowed.

    (This is indeed related to imaplib module ;))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.