我正在尝试向某人发送 Gmail 文本
I am trying to send a gmail text to someone
所以我试图发送它给了我这个错误
这是错误
Traceback (most recent call last):
File "C:\Users470\AppData\Local\Programs\Python\Python39\mess.py", line 6, in <module>
server = smtplib.SMTP(smtpServer,25)
File "C:\Users470\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 258, in __init__
raise SMTPConnectError(code, msg)
smtplib.SMTPConnectError: (451, b'Request action aborted on MFE proxy, SMTP server is not
available.')
这是我的代码
import smtplib
smtpServer='smtp.yourdomain.com'
fromAddr='imranalubankudi@gmail.com'
toAddr='gmmeremnwanne@gmail.com'
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(smtpServer,25)
server = smtplib.SMTP(smtpServer,25)
server.ehlo()
server.starttls()
server.sendmail(fromAddr, toAddr, text)
server.quit()
尝试将端口更改为 587。另外,您的 smtpServer
看起来不适合 gmail。
server = smtplib.SMTP('smtp.gmail.com', 587)
您还需要登录会话。
这是一个通过 gmail 发送简单文本邮件的简单函数。
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_mail(send_from, send_to, subject, body):
#The mail addresses and password
sender_pass = 'your_gmail_password'
#Setup the MIME
message = MIMEMultipart()
message['From'] = send_from
message['To'] = send_to
message['Subject'] = subject
message.attach(MIMEText(body, 'plain'))
session = smtplib.SMTP('smtp.gmail.com', 587)
session.starttls()
session.login(send_from, sender_pass)
text = message.as_string()
session.sendmail(send_from, send_to, text)
session.quit()
所以我试图发送它给了我这个错误 这是错误
Traceback (most recent call last):
File "C:\Users470\AppData\Local\Programs\Python\Python39\mess.py", line 6, in <module>
server = smtplib.SMTP(smtpServer,25)
File "C:\Users470\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 258, in __init__
raise SMTPConnectError(code, msg)
smtplib.SMTPConnectError: (451, b'Request action aborted on MFE proxy, SMTP server is not
available.')
这是我的代码
import smtplib
smtpServer='smtp.yourdomain.com'
fromAddr='imranalubankudi@gmail.com'
toAddr='gmmeremnwanne@gmail.com'
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(smtpServer,25)
server = smtplib.SMTP(smtpServer,25)
server.ehlo()
server.starttls()
server.sendmail(fromAddr, toAddr, text)
server.quit()
尝试将端口更改为 587。另外,您的 smtpServer
看起来不适合 gmail。
server = smtplib.SMTP('smtp.gmail.com', 587)
您还需要登录会话。
这是一个通过 gmail 发送简单文本邮件的简单函数。
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_mail(send_from, send_to, subject, body):
#The mail addresses and password
sender_pass = 'your_gmail_password'
#Setup the MIME
message = MIMEMultipart()
message['From'] = send_from
message['To'] = send_to
message['Subject'] = subject
message.attach(MIMEText(body, 'plain'))
session = smtplib.SMTP('smtp.gmail.com', 587)
session.starttls()
session.login(send_from, sender_pass)
text = message.as_string()
session.sendmail(send_from, send_to, text)
session.quit()