Reputation: 55
I'm a newbie to Python so having some difficulty in sending mail using python script .I'm using mime and smtplib .For some reason I'm getting unable to send and my mail doesn't have any body .attaching the code. Any idea ??
import smtplib
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
hostname='hello'
sender = '[email protected]'
receivers = ['[email protected]']
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = receivers
msg['Subject'] = "Upgrade started for"+hostname+"."
try:
smtpObj = smtplib.SMTP('mail.xxx.com',25)
smtpObj.sendmail(sender, receivers, msg.as_string())
print "Successfully sent email"
except:
print "Error: unable to send email"
Upvotes: 2
Views: 453
Reputation: 2756
I have this option works by postfix
:
import smtplib
from email.mime.text import MIMEText
s = smtplib.SMTP()
s.connect('localhost') # connect to the SMTP server
doc = "<html><h1>Test title</h1></html>"
while True:
msg = MIMEText( doc, _subtype='html', _charset='utf-8' )
s.sendmail('[email protected]', ['[email protected]'], msg.as_string())
s.quit()
Upvotes: 1