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.