Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 16, 2021 15:39
Show Gist options
  • Save aspose-com-gists/0987ed331c4b11d0d17dbddcb323c6c8 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/0987ed331c4b11d0d17dbddcb323c6c8 to your computer and use it in GitHub Desktop.
Connect to SMTP Server and Send Emails in Python
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
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