首页 > 解决方案 > 使用 python 脚本从 CPanel 电子邮件发送电子邮件

问题描述

我正在尝试从 Cpanel 电子邮件发送电子邮件,但我尝试的所有操作都面临同样的错误 [Errno 11001] getaddrinfo failed

这是我的代码,我在 Google 域中尝试过,它工作正常,但 Cpanel 不工作?有没有办法使用 python 发送电子邮件?

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
from email.mime.image import MIMEImage
email_user = 'something@Mydomain.com'
email_password = 'password'

email_send = "someemail@gmail.com"
subject = "Testing 2"
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject
h = str("Holder")
c = str("course")
t = str("trainer")
html = """\
<html>
  <head></head>
  <body>
    <p >Hello {h} This {t} we need your conf. on {c} </p>
  </body>
</html>
""".format(h=h , c=c , t=t) 
    
msg.attach(MIMEText(html,'html'))
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(email_user,email_password)
server.sendmail(email_user,email_send,msg.as_string())
server.quit()

所以你怎么看?

标签: pythonemailcpanel

解决方案


是的,你必须改变server = smtplib.SMTP('yourDomain.com',25)


推荐阅读