
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Sending an HTML e-mail using Python
When you send a text message using Python, then all the content are treated as simple text. Even if you include HTML tags in a text message, it is displayed as simple text and HTML tags will not be formatted according to HTML syntax. But Python provides option to send an HTML message as actual HTML message.
While sending an e-mail message, you can specify a Mime version, content type and character set to send an HTML e-mail.
Example
Following is the example to send HTML content as an e-mail. Try it once −
#!/usr/bin/python import smtplib message = """From: From Person <from@fromdomain.com> To: To Person <to@todomain.com> MIME-Version: 1.0 Content-type: text/html Subject: SMTP HTML e-mail test This is an e-mail message to be sent in HTML format <b>This is HTML message.</b> <h1>This is headline.</h1> """ try: smtpObj = smtplib.SMTP('localhost') smtpObj.sendmail(sender, receivers, message) print "Successfully sent email" except SMTPException: print "Error: unable to send email"
- Related Articles
- Sending Attachments as an E-mail using Python
- What is an Electronic Mail (E-Mail)?
- Sending an HTML Message using Perl
- How should I validate an e-mail address in Android using Kotlin?.
- How should I validate an e-mail address in Android?
- Sending an Attachment with email using Perl
- How to hide e-mail address from an unauthorized user in JavaScript?
- Send mail from your Gmail account using Python
- Explain the E-Mail Format in Computer Network.
- Sending an itab to SAP Spool using ABAP method
- Send mail with attachment from your Gmail account using Python
- Sending an Intent to browser to open specific URL using Kotlin.
- Sending a Plain Message using Perl
- Sending HTTP error code using Express.js
- How to get the Android device's primary e-mail address?

Advertisements