'Sending email via smtplib in Python
I have a problem with sending email via smtplib. I am trying to use company smtp host. I have following example code:
import smtplib
import getpass as gp
sender = '[email protected]'
receivers = ['[email protected]']
message = """From: From sender
To: [email protected]
Subject: SMTP e-mail test
This is a test e-mail message.
"""
pw = gp.getpass('Pass:')
smtp_ip="smtp.company.com"
smtp_port=num
try:
smtpObj = smtplib.SMTP(smtp_ip, smtp_port)
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.login(sender, pw)
smtpObj.sendmail(sender, receivers, message)
smtpObj.close()
print ("Successfully sent email")
except Exception as e:
print ("Error: unable to send email", e)
After running this I am getting following error
Error: unable to send email {'[email protected]': (453, b'4.7.1 <[email protected]>: Sender address rejected: not owned by user [email protected]')}
I was even using the same address but still there is a problem with this ownership. Have someone any idea what can be wrong here? Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
