Skip to content

Instantly share code, notes, and snippets.

@amaudy
Last active April 12, 2016 02:56
Show Gist options
  • Save amaudy/957298cd69f3609ac01eab333084431e to your computer and use it in GitHub Desktop.
Save amaudy/957298cd69f3609ac01eab333084431e to your computer and use it in GitHub Desktop.
simple python script send email via smtp with user/pass
from smtplib import SMTP
import datetime
debuglevel = 0
smtp = SMTP()
smtp.set_debuglevel(debuglevel)
smtp.connect('YOUR.MAIL.SERVER', 26)
smtp.login('USERNAME@DOMAIN', 'PASSWORD')
from_addr = "John Doe <[email protected]>"
to_addr = "[email protected]"
subj = "hello"
date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" )
message_text = "Hello\\nThis is a mail from your server\\n\\nBye\\n"
msg = "From: %s\\nTo: %s\\nSubject: %s\\nDate: %s\\n\\n%s" \
% ( from_addr, to_addr, subj, date, message_text )
smtp.sendmail(from_addr, to_addr, msg)
smtp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment