SMTP适用于Linux但不适用于Mac

时间:2018-04-15 08:37:03

标签: python linux macos email smtp

当我在Linux中运行以下代码时,它会发送电子邮件,但是,在Mac中,它无法在行服务器上运行= smtplib.SMTP(" smtp.gmail.com",&# 34; 587&#34)

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import subprocess as s
import sys
import os

def send_email(predicted_change, sentiment, coin, toaddr):
     fromaddr = "****@gmail.com"
     msg = MIMEMultipart()
     msg['From'] = fromaddr
     msg['To'] = toaddr
     msg['Subject'] = "Predicted Price Change Of " + coin

     body = "The sentiment of the last 60 minutes for " + coin + " is : " + 
     sentiment + " - The predicted change in price is : " + predicted_change
     msg.attach(MIMEText(body, 'plain'))
     server = smtplib.SMTP("smtp.gmail.com", "587")
     server.starttls()
     server.ehlo()
     server.login(fromaddr, "****")
     text = msg.as_string()
     print(text)
     server.sendmail(fromaddr, toaddr, text)
     server.quit()
     print("Over")

我收到此错误

 socket.error: [Errno 60] Operation timed out

0 个答案:

没有答案