【问题标题】:Web2Py IOError: [Errno socket error] [Errno 11004] getaddrinfo failed error for sending emailWeb2Py IOError:[Errno 套接字错误] [Errno 11004] getaddrinfo 发送电子邮件失败错误
【发布时间】:2014-05-15 12:58:46
【问题描述】:

我收到以下错误:

警告:web2py:Mail.send 失败:[Errno 11004] getaddrinfo failed

以下代码:

mail = Mail()
mail.settings.server = 'smtp.gmail.com:587'
mail.settings.sender = 'email@gmail.com'
mail.settings.login = 'email@gmail.com:password'

mail.send(to=[email],subject= 'TEST',message='helloWorld')

有人可以帮助我吗?我似乎找不到任何关于 getaddrinfo 是什么以及代码中发生错误的位置的文档。

谢谢!

【问题讨论】:

    标签: python email gmail web2py getaddrinfo


    【解决方案1】:

    我使用 smtplib 来做。

    # here i check if i send succesfully.
    server = smtplib.SMTP(HOST)
    # server.login(username, password)  # optional
    try:
        toaddr = TO
        cc = [CC]
        bcc = ['']
        toaddrs = [toaddr] + cc + bcc
        failed = server.sendmail(FROM, toaddrs, msg.as_string())
        server.close()
        statusemail= "Email enviado com sucesso para %s" % TO
        print statusemail
        return statusemail
    except Exception, e:
        errorMsg = "Unable to send email. Error: %s" % str(e)
        return errorMsg
    ##############################################################
    #example code to test smtplib
    import smtplib
    # Specifying the from and to addresses
    fromaddr = 'fromuser@gmail.com'
    toaddrs  = 'touser@gmail.com'
    # Writing the message (this message will appear in the email)
    msg = 'Enter you message here'
    # Gmail Login
    username = 'username'
    password = 'password'
    # Sending the mail  
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    server.login(username,password)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()
    

    来源:link

    【讨论】:

      【解决方案2】:

      这是您计算机网络设置的问题。 你的代码没有问题。

      关于getaddrinfohere的信息

      如果您使用的是类似 linux/unix 的系统 - 您可以尝试nslookup smtp.gmail.com

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多