SlideShare a Scribd company logo
Python session.11 By Shanmugam
AGENDA
Email using SMTP
HTML e-mail
Python Sending Email using SMTP
●
Simple Mail Transfer Protocol (SMTP) is a protocol,
which handles sending e-mail and routing e-mail between
mail servers.
●
Python provides smtplib module, which defines an SMTP
client session object that can be used to send mail to any
Internet machine with an SMTP.
import smtplib
smtpObj = smtplib.SMTP( [host [, port [,local_hostname]]] )
host: This is the host running your SMTP server. You can
specifiy IP address of the host or a domain name like
tutorialspoint.com. This is optional argument.
●
port: If you are providing host argument, then you need to
specify a port, where SMTP server is listening. Usually
this port would be 25.
●
local_hostname: If your SMTP server is running on your
local machine, then you can specify just localhost as of
this option.
●
An SMTP object has an instance method called
sendmail, which will typically be used to do the work of
mailing a message. It takes three parameters:
●
The sender - A string with the address of the sender.
●
The receivers - A list of strings, one for each recipient.
●
The message - A message as a string formatted as
specified in the various RFCs.
import smtplib
sender = 'from@fromdomain.com'
receivers = ['to@todomain.com']
message = """From: From Person
<from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
Sending an HTML e-mail using Python:
While sending an e-mail message, you can specify a Mime version,
content type and character set to send an HTML e-mail.
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"
Python session.11 By Shanmugam

More Related Content

PPT
Socket programming
ODP
Osrf msg life_cycle
PPTX
PPT
Easy Steps to implement UDP Server and Client Sockets
PDF
Should it be routine to use coroutines?
PPT
Networking & Socket Programming In Java
PDF
Java sockets
Socket programming
Osrf msg life_cycle
Easy Steps to implement UDP Server and Client Sockets
Should it be routine to use coroutines?
Networking & Socket Programming In Java
Java sockets

What's hot (19)

PPTX
Implement server push in flask framework
ODP
Building Netty Servers
PDF
Network programming Using Python
PPT
Socket programming-tutorial-sk
PDF
Asynchronous, Event-driven Network Application Development with Netty
PDF
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
PDF
JSON-RPC - JSON Remote Procedure Call
PDF
Locker: distributed consistent locking
PDF
Zmq in context of openstack
PDF
Netty: asynchronous data transfer
PPTX
Build reliable, traceable, distributed systems with ZeroMQ
PPTX
ZeroMQ: Super Sockets - by J2 Labs
PDF
JSON-RPC Proxy Generation with PHP 5
PDF
Socket programming using java
PPTX
Network programming using python
PDF
Socket programming-in-python
PDF
gRPC in Go
PPTX
zeromq
PPT
Tcp sockets
Implement server push in flask framework
Building Netty Servers
Network programming Using Python
Socket programming-tutorial-sk
Asynchronous, Event-driven Network Application Development with Netty
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
JSON-RPC - JSON Remote Procedure Call
Locker: distributed consistent locking
Zmq in context of openstack
Netty: asynchronous data transfer
Build reliable, traceable, distributed systems with ZeroMQ
ZeroMQ: Super Sockets - by J2 Labs
JSON-RPC Proxy Generation with PHP 5
Socket programming using java
Network programming using python
Socket programming-in-python
gRPC in Go
zeromq
Tcp sockets
Ad

Similar to Python session.11 By Shanmugam (20)

PPTX
Sending Email
DOC
vishal_sharma: python email sending software
PDF
Lecture 9 electronic_mail_representation_and_transfer
PDF
Lec 9(Emails)
PDF
Internet technology unit 6
PPT
internet applications
PPTX
7_Chapter 7_Email.pptx
PPTX
Simple Mail Transfer Protocol
PPSX
SMTP(simple mail transfer protocol).ppsx
PPT
Mail services
PPTX
Technical Background Overview Ppt
PPT
SMTP(true)
PPT
E mail transfer .74
PDF
i &lt;3 email
PPT
26 (SMTP and FTP) 76 slides 2.ppt 26 (SMTP and FTP) 76 slides 2.ppt
PPT
jhvkjk lbkbl jblkj bkjbkjb kjbk blk kjblkjb
PPT
Malware and Software Vulnerability Analysis
PPT
CAP6135 - Malware and Software Vulnerability Analysis
PPTX
Simple Mail Transfer Protocol
PPT
Malware and Software Vulnerability Analysis Spam and Phishing .ppt
Sending Email
vishal_sharma: python email sending software
Lecture 9 electronic_mail_representation_and_transfer
Lec 9(Emails)
Internet technology unit 6
internet applications
7_Chapter 7_Email.pptx
Simple Mail Transfer Protocol
SMTP(simple mail transfer protocol).ppsx
Mail services
Technical Background Overview Ppt
SMTP(true)
E mail transfer .74
i &lt;3 email
26 (SMTP and FTP) 76 slides 2.ppt 26 (SMTP and FTP) 76 slides 2.ppt
jhvkjk lbkbl jblkj bkjbkjb kjbk blk kjblkjb
Malware and Software Vulnerability Analysis
CAP6135 - Malware and Software Vulnerability Analysis
Simple Mail Transfer Protocol
Malware and Software Vulnerability Analysis Spam and Phishing .ppt
Ad

More from Navaneethan Naveen (20)

PPT
Class inheritance 13 session - SHAN
PPT
Python session 12
PPT
Python session 11
PPT
V irtualisation.1
PPT
Virtualisation-11
PPT
Networking session-4-final by aravind.R
PPT
Networking session3
PPT
WIN-ADCS-10
PPT
Python session 10
PPT
Python multithreading session 9 - shanmugam
PPT
Python session 8
PPT
PPT
Virtualization session 8
PDF
Virtualization session 7 by Gugan
PPT
Python session 7 by Shan
PPT
Virtualization s4.1
PPT
Python session 6
PPT
Gpo windows(4)
PPTX
Windows session 5 : Basics of active directory
PPT
Network session 1 OSI Model
Class inheritance 13 session - SHAN
Python session 12
Python session 11
V irtualisation.1
Virtualisation-11
Networking session-4-final by aravind.R
Networking session3
WIN-ADCS-10
Python session 10
Python multithreading session 9 - shanmugam
Python session 8
Virtualization session 8
Virtualization session 7 by Gugan
Python session 7 by Shan
Virtualization s4.1
Python session 6
Gpo windows(4)
Windows session 5 : Basics of active directory
Network session 1 OSI Model

Recently uploaded (20)

PDF
Trump Administration's workforce development strategy
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
01-Introduction-to-Information-Management.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Cell Structure & Organelles in detailed.
Trump Administration's workforce development strategy
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Final Presentation General Medicine 03-08-2024.pptx
History, Philosophy and sociology of education (1).pptx
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
01-Introduction-to-Information-Management.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Weekly quiz Compilation Jan -July 25.pdf
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Cell Structure & Organelles in detailed.

Python session.11 By Shanmugam

  • 3. Python Sending Email using SMTP ● Simple Mail Transfer Protocol (SMTP) is a protocol, which handles sending e-mail and routing e-mail between mail servers. ● Python provides smtplib module, which defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP.
  • 4. import smtplib smtpObj = smtplib.SMTP( [host [, port [,local_hostname]]] ) host: This is the host running your SMTP server. You can specifiy IP address of the host or a domain name like tutorialspoint.com. This is optional argument. ● port: If you are providing host argument, then you need to specify a port, where SMTP server is listening. Usually this port would be 25. ● local_hostname: If your SMTP server is running on your local machine, then you can specify just localhost as of this option.
  • 5. ● An SMTP object has an instance method called sendmail, which will typically be used to do the work of mailing a message. It takes three parameters: ● The sender - A string with the address of the sender. ● The receivers - A list of strings, one for each recipient. ● The message - A message as a string formatted as specified in the various RFCs.
  • 6. import smtplib sender = '[email protected]' receivers = ['[email protected]'] message = """From: From Person <[email protected]> To: To Person <[email protected]> Subject: SMTP e-mail test This is a test e-mail message. """
  • 7. try: smtpObj = smtplib.SMTP('localhost') smtpObj.sendmail(sender, receivers, message) print "Successfully sent email" except SMTPException: print "Error: unable to send email"
  • 8. Sending an HTML e-mail using Python: While sending an e-mail message, you can specify a Mime version, content type and character set to send an HTML e-mail. import smtplib message = """From: From Person <[email protected]> To: To Person <[email protected]> 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
  • 9. <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"