如何将电子邮件从计算机发送到gmail?

问题描述

我想构建smtp服务器,这是我的代码

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

# Create the message
msg = MIMEText('This is the body of the message.')
msg['To'] = email.utils.formataddr(('Recipient','[email protected]'))
msg['From'] = email.utils.formataddr(('mygmail','[email protected]'))
msg['Subject'] = 'Simple test message'

server = smtplib.SMTP('my_ip',25)
server.set_debuglevel(True) # show communication with the server
try:
    server.sendmail('[email protected]',['[email protected]'],msg.as_string())
finally:
    server.quit()

当我也是听众的时候效果很好 这是我的python2监听代码

import smtpd
import asyncore

class CustomSMTPServer(smtpd.SMTPServer):

    def process_message(self,peer,mailfrom,rcpttos,data):
        print 'Receiving message from:',peer
        print 'Message addressed from:',mailfrom
        print 'Message addressed to  :',rcpttos
        print 'Message length        :',len(data)
        print '\n\n',data
    print '\n__________________________________________________________________________________\n'
        return

server = CustomSMTPServer(('192.168.200.14',25),None)

asyncore.loop()

但是如果出现此错误,我是否将此代码发送到我的gmail帐户

send: 'ehlo [127.0.1.1]\r\n'
reply: b'250-smtp.gmail.com at your service,[79.181.102.40]\r\n'
reply: b'250-SIZE 35882577\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH\r\n'
reply: b'250-ENHANCEDSTATUSCODES\r\n'
reply: b'250-PIPELINING\r\n'
reply: b'250-CHUNKING\r\n'
reply: b'250 SMTPUTF8\r\n'
reply: retcode (250); Msg: b'smtp.gmail.com at your service,[79.181.102.40]\nSIZE 35882577\n8BITMIME\nAUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH\nENHANCEDSTATUSCODES\nPIPELINING\nCHUNKING\nSMTPUTF8'
send: 'mail FROM:<[email protected]> size=241\r\n'
reply: b'530-5.7.0 Authentication required. Learn more at\r\n'
reply: b'530 5.7.0  https://support.google.com/mail/?p=WantAuthError a83sm3060044wmh.48 - gsmtp\r\n'
reply: retcode (530); Msg: b'5.7.0 Authentication required. Learn more at\n5.7.0  https://support.google.com/mail/?p=WantAuthError a83sm3060044wmh.48 - gsmtp'
send: 'rset\r\n'
reply: b'250 2.1.5 Flushed a83sm3060044wmh.48 - gsmtp\r\n'
reply: retcode (250); Msg: b'2.1.5 Flushed a83sm3060044wmh.48 - gsmtp'
send: 'quit\r\n'
reply: b'221 2.0.0 closing connection a83sm3060044wmh.48 - gsmtp\r\n'
reply: retcode (221); Msg: b'2.0.0 closing connection a83sm3060044wmh.48 - gsmtp'
Traceback (most recent call last):
  File "send.py",line 14,in <module>
    server.sendmail('[email protected]',['[email protected]'],msg.as_string())
  File "/usr/lib/python3.8/smtplib.py",line 871,in sendmail
    raise SMTPSenderRefused(code,resp,from_addr)
smtplib.SMTPSenderRefused: (530,b'5.7.0 Authentication required. Learn more at\n5.7.0  https://support.google.com/mail/?p=WantAuthError a83sm3060044wmh.48 - gsmtp','[email protected]')

我尝试通过nc收听以了解gmail如何发送电子邮件,但看不到 我尝试将SSL与端口465一起使用,但出现相同的错误

我如何从我的smtp服务器向gmail发送电子邮件

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)