python send a message 554DT: SPM Resolved

  Description: This example uses a mailbox 163

First, the error message

  Use SMTP mail encounter the following error:

  554, b'DT:SPM 163 smtp10,DsCowACXeOtmjRRdsY8aCw--.21947S2 1561628007,please see http://mail.163.com/help/help_spam_16.htm?ip=36.110.94.251&hostid=smtp10&time=1561628007'

Second, the investigation and the reasons

  163 E-mail settings 1. Check whether the authorization code, authorization code right. Not being given: 535, b'Error: authentication failed The '

  2. Check Code Message Format Specification

    The following section of code, the tutorial novice posted header. Look Sent Items indeed shows the sender's alias (display behalf ), the recipient sees the sender's nickname is your own. As shown below:

# -*- coding: utf-8 -*-
# Nola

import smtplib
from email.mime.text import MIMEText
from email.header import Header
import time

mail_server = "smtp.163.com"
mail_port = 25
sender = "[email protected]"
sender_password = "xxxxxx"  # 授权码
receivers = "[email protected]"


Message = MimeText ( ' the Python sending test messages ... ' , ' Plain ' , ' UTF-. 8 ' )
 # Message [ 'the From'] = SENDER 
# Message [ 'the To'] = Receivers 
Message [ ' the From ' ] = Header ( " novice tutorial " , ' UTF-. 8 ' )
message['To'] = Header("测试", 'utf-8')

send_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
Subject = ' Test Mail ' + The send_time
message['Subject'] = subject


try:
    smtp_obj = smtplib.SMTP()
    smtp_obj.connect(mail_server, mail_port)
    smtp_obj.login(sender, sender_password)
    smtp_obj.sendmail(sender, [receivers], message.as_string())
    print('success!')
except smtplib.SMTPException as e:
    print('failure!')
    print(e)

 

  Focus is on: After receiving a few emails, receive, and for recipients not received, 163 ban guess is made. Point figure above helps you can see the figure below, the goodwill will disguise misunderstanding.

Third, the solution

  From and To sender and recipient use a real e-mail address , you can send success.

  

# -*- coding: utf-8 -*-
# Nola

import smtplib
from email.mime.text import MIMEText
import time

mail_server = "smtp.163.com"
mail_port = 25
sender = "[email protected]"
sender_password = "xxxxxx"  # 授权码
receivers = "[email protected]"


Message = MimeText ( ' the Python sending test messages ... ' , ' Plain ' , ' UTF-. 8 ' )
message['From'] = sender
message['To'] = receivers

send_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
Subject = ' Test Mail ' + The send_time
message['Subject'] = subject


try:
    smtp_obj = smtplib.SMTP()
    smtp_obj.connect(mail_server, mail_port)
    smtp_obj.login(sender, sender_password)
    smtp_obj.sendmail(sender, [receivers], message.as_string())
    print('success!')
except smtplib.SMTPException as e:
    print('failure!')
    print(e)

 

 

 

  

  

Guess you like

Origin www.cnblogs.com/NolaLi/p/11098670.html