Last active
November 5, 2018 09:32
-
-
Save ichux/6cd113d01db12c6159869c7a3c214434 to your computer and use it in GitHub Desktop.
send localmails
This file contains 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 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() |
This file contains 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
MAIL FROM: sender@example.com | |
RCPT TO: rcpt@example.com | |
DATA | |
Hello for the terminal on Mac | |
. | |
QUIT |
This file contains 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
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 |
This file contains 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
# run server | |
sudo python -m smtpd -c DebuggingServer -n localhost:25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run the server before running the Python file