Last active
April 12, 2016 02:56
-
-
Save amaudy/957298cd69f3609ac01eab333084431e to your computer and use it in GitHub Desktop.
simple python script send email via smtp with user/pass
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
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