Python module: smtplib module

Source: Internet
Author: User

1. Using the local SendMail protocol for Mail sending

Format (1): Smtpobj=smtplib. SMTP ([host [, Port [, Local_hostname]])

HOST:SMTP the IP address or domain name of the server host

Port: Port number of the service (default is 25)

Local_hostname: The address of the server (localhost by default)


Format (2): Smtp.sendmail (FROM_ADDR), To_addrs,msg[,mail_options,rcpt_options]

FROM_ADDR: Address sent by mail

TO_ADDR: Mail Receive address

Msg: Send Message


[Email protected] tmp]# vim smtplib.py

#!/bin/env python
#!-*-Coding:utf-8-*-

Import Smtplib
From Email.mime.text import Mimetext
From Email.header Import Header

sender= ' [email protected] '
receivers= ' [email protected] '
Message=mimetext (' Python Mail send Test ... ', ' plain ', ' utf-8 ')
message[' from ']=header (' Rookie tutorial ', ' Utf-8 ')
message[' to ']=header (' Test ', ' utf-8 ')

subject= ' Python SMTP mail test '
message[' Subject ']=header (Subject, ' utf-8 ')

Try
Smtpobj=smtplib. SMTP (' localhost ')
Smtpobj.sendmail (sender,receivers,message.as_string ())
Print "Mail sent successfully"
Except Smtplib. Smtpexception:
Print "Error: unable to send mail"
[email protected] tmp]# python smtplib.py
Message sent successfully

[Email protected] tmp]#

This article is from the "Days Together" blog, please be sure to keep this source http://tongcheng.blog.51cto.com/6214144/1766856

Python module: smtplib module

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.