Skip to content

Instantly share code, notes, and snippets.

@ichux
Last active November 5, 2018 09:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichux/6cd113d01db12c6159869c7a3c214434 to your computer and use it in GitHub Desktop.
Save ichux/6cd113d01db12c6159869c7a3c214434 to your computer and use it in GitHub Desktop.
send localmails
import email.utils
import smtplib
from email.mime.text import MIMEText
# Create the message
msg = MIMEText('Hello SMTPD!')
msg['To'] = email.utils.formataddr(("Local Mail", "localmail@localhost"))
msg['From'] = email.utils.formataddr(('Chukwudi Nwachukwu', 'chukwudinwachukwu@localhost'))
msg['Subject'] = 'Local mail using SMTP'
server = smtplib.SMTP('localhost', 25)
# show communication with the server
server.set_debuglevel(True)
try:
server.sendmail('chukwudinwachukwu@localhost', ["replyto@localhost"], msg.as_string())
finally:
server.quit()
MAIL FROM: sender@example.com
RCPT TO: rcpt@example.com
DATA
Hello for the terminal on Mac
.
QUIT
MAIL FROM:<chukwudinwachukwu@localhost>
RCPT TO:<replyto@localhost>
DATA
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
To: Local Mail <localmail@localhost>
From: Chukwudi Nwachukwu <chukwudinwachukwu@localhost>
Subject: Local mail using SMTP
Hello SMTP from Mac terminal!
.
QUIT
# run server
sudo python -m smtpd -c DebuggingServer -n localhost:25
@ichux
Copy link
Author

ichux commented Oct 29, 2018

run the server before running the Python file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment