Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 25, 2022 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/6352ca6844ca0c4643e38451ecca76c2 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/6352ca6844ca0c4643e38451ecca76c2 to your computer and use it in GitHub Desktop.
Connect to SMTP Server in Python | Send Emails via SMTP
from aspose.email import SmtpClient, SecurityOptions
# Create SMTP client
client = SmtpClient()
# Set properties
client.host = "smtp.gmail.com"
client.port = 587
client.username = "username"
client.password = "password"
# Set security options
client.security_options = SecurityOptions.SSLEXPLICIT
import aspose.email as ae
# Create email
eml = ae.MailMessage()
eml.subject = "Message with Plain Text Body"
eml.body = "This is plain text body."
eml.from_address = "from@gmail.com"
eml.to.append(ae.MailAddress("to@gmail.com", "Recipient 1"))
# Configure SMTP Client
client = ae.SmtpClient("smtp.gmail.com", 995, "username", "password")
client.security_options = ae.SecurityOptions.AUTO
# Send email
client.send(eml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment