smtplib.SMTPRecipientsRefused: Recipient address rejected: Access denied ,smtplib python

时间:2018-12-19 11:34:30

标签: python sendmail smtplib

Im just learning to send mail, i have some code , but it showing authentication failure.

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders

msg = MIMEMultipart()
sender='mymailid.cp@ac.com'
recipients ='recievermailid@ac.com'
server=smtplib.SMTP('server.com',port)
server.ehlo()
server.starttls()
server.ehlo()
server.login('mymailid.cp@ac.com','xyz@123')

msg['Subject'] = 'ERROR'
msg['From'] = sender
msg['To'] = recipients


filename = r'C:\Users\S\ab.xlsx'
attachment = open(r'C:\Users\S\ab.xlsx', 'rb')
xlsx = MIMEBase('application','vnd.openxmlformats-officedocument.spreadsheetml.sheet')
xlsx.set_payload(attachment.read())

encoders.encode_base64(xlsx)
xlsx.add_header('Content-Disposition', 'attachment', filename=filename)
msg.attach(xlsx)

server.sendmail(sender, recipients, msg.as_string())
server.quit()
attachment.close()

To solve the aunthetication fialure error, i removed server.login() section [enter link description here][from this, i learnt that server.login() is not required.] After removing that code , i got error 'raise SMTPRecipientsRefused(senderrs) smtplib.SMTPRecipientsRefused: {'recievermailid@ac.com': (554, b'5.7.1 : Recipient address rejected: Access denied')} '

Before marking it as a duplicate , please read the issue completely. Here i can't send mail from one to another.it showing access denied as error.

0 个答案:

没有答案