0

I'm trying to send an e-mail to a distribution list using smtplib. The following is my code:

to = ['distlist@company.com']
    username = 'user'
    password = 'pw'
    smtpserver = smtplib.SMTP("server", 587)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(username, password)
    header = 'To:'
    for address in to:
        header += address + ' '
    header += '\n' + 'From: ' + username + '\n' + 'Subject:testing \n'
    msg = header + ''

    smtpserver.sendmail(username, to, msg)

    smtpserver.close()

When my code runs the e-mail tries to send through microsoft outlook. I get an e-mail from outlook that says: The e-mail address you entered couldn't be found. Please check the recipient's e-mail address and try to resend the message. If the problem continues, please contact your helpdesk.

But the e-mail address for the distribution list is definitely correct.

Thoughts? Any help would be appreciated.

EgoKilla
  • 131
  • 12
  • You get the email/auto-reply from Outlook indicating that e.g., `'distlist@company.com'` can't be found? – David Zemens Sep 15 '15 at 18:23
  • Just to hazard a guess here is this distribtion list part of the "Global Address Book" or otherwise publicly available? Or is it something that's local to *your* machine, in which case it might not work via SMTP? (I'm kinda out of my element on this one, just tossing out some ideas) – David Zemens Sep 15 '15 at 18:26
  • Try sending without building the header?: `smtpserver.sendmail(username, to, 'test')`. Another thing I'm not sure about, but should it be: `to = ['']`? – David Zemens Sep 15 '15 at 18:32
  • `smtpserver.ehlo` seems to be missing parentheses. – Robᵩ Sep 15 '15 at 18:36
  • So the distribution list is in the global address book. This exact code works if I try to send the e-mail to an individual but for some reason the distribution e-mail address messes it up. – EgoKilla Sep 15 '15 at 18:43

0 Answers0