Learn how to connect SMTP server and send email in Python: https://blog.aspose.com/2021/12/16/connect-to-smtp-server-using-python/
Last active
December 16, 2021 15:39
-
-
Save aspose-com-gists/0987ed331c4b11d0d17dbddcb323c6c8 to your computer and use it in GitHub Desktop.
Connect to SMTP Server and Send Emails in Python
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 aspose.email as ae | |
from aspose.email import SecurityOptions, SmtpClient | |
# create SMTP client | |
client = SmtpClient() | |
# set host, port, username and password | |
client.host = "smtp.gmail.com" | |
client.port = 587 | |
client.username = "username" | |
client.password = "password" | |
# set security options for SSL emabled server | |
client.security_options = SecurityOptions.SSLEXPLICIT | |
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 aspose.email as ae | |
from aspose.email import SecurityOptions, SmtpClient | |
# create a new message | |
eml = ae.MailMessage() | |
# set subject, body, to and from addresses | |
eml.subject = "Message with Html Body" | |
eml.is_body_html = True | |
eml.html_body = "<html><body>This is the <b>HTML</b>body</body></html>" | |
eml.from_address = "from@gmail.com" | |
eml.to.append(ae.MailAddress("to@gmail.com", "Recipient 1")) | |
# send email using Smtp Client | |
client = SmtpClient("smtp.gmail.com", 995, "username", "password") | |
client.security_options = SecurityOptions.AUTO | |
client.send(eml) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment