Created
September 14, 2012 04:56
-
-
Save 1900/3719878 to your computer and use it in GitHub Desktop.
send email in Python via SMTPLIB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
import sys | |
import email.mime.text | |
mail_username='[email protected]' | |
mail_password='password' | |
from_addr = mail_username | |
to_addrs=('[email protected]') | |
HOST = 'smtp.gmail.com' | |
PORT = 25 | |
# Create SMTP Object | |
smtp = smtplib.SMTP() | |
print 'connecting ...' | |
# show the debug log | |
smtp.set_debuglevel(1) | |
# connet | |
try: | |
print smtp.connect(HOST,PORT) | |
except: | |
print 'CONNECT ERROR ****' | |
# gmail uses ssl | |
smtp.starttls() | |
# login with username & password | |
try: | |
print 'loginning ...' | |
smtp.login(mail_username,mail_password) | |
except: | |
print 'LOGIN ERROR ****' | |
# fill content with MIMEText's object | |
msg = email.mime.text.MIMEText('Hi ,All') | |
msg['From'] = from_addr | |
msg['To'] = ';'.join(to_addrs) | |
msg['Subject']='this is test msg' | |
print msg.as_string() | |
smtp.sendmail(from_addr,to_addrs,msg.as_string()) | |
smtp.quit() |
Please read the technical whitepaper at https://forwardemail.net/technical-whitepaper.pdf cc @Dadiya-Harsh
@titanism ok, thanks for sharing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@titanism why should i use @forwardemail , how is it better?