V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
o618
V2EX  ›  问与答

在sendmail.py下配置gmail的smtp,弄了一晚上都没成功,请问问题出在哪里‘?

  •  
  •   o618 · 2014-01-22 09:33:48 +08:00 · 2614 次点击
    这是一个创建于 3759 天前的主题,其中的信息可能已经有所发展或是发生改变。
    具体配置如下:

    send_mail_host = 'smtp.gmail.com'
    send_mail_user = 'goodman'
    send_mail_user_name = u'goodman bbs'
    send_mail_pswd = '12345678'
    send_mail_postfix = 'gmail.com'
    get_mail_user = 'goodman'
    charset = 'utf-8'

    get_mail_postfix = 'gmail.com'
    get_mail_host = 'smtp.gmail.com'
    def send(sub, content, reciver = get_mail_user + get_mail_postfix):
    send_mail_address = send_mail_user_name + '<' + send_mail_user + '@' + send_mail_postfix + '>'
    msg = email.mime.text.MIMEText(content,'html',charset)
    msg['Subject'] = email.Header.Header(sub,charset)
    msg['From'] = send_mail_address
    msg['to'] = to_adress = reciver
    try:
    stp = smtplib.SMTP('smtp.gmail.com',587)
    stp.connect(send_mail_host)
    stp.login(send_mail_user,send_mail_pswd)
    stp.sendmail(send_mail_address,to_adress,msg.as_string())
    stp.close()
    return True
    except Exception,e:
    print(e)
    return False
    8 条回复    1970-01-01 08:00:00 +08:00
    durrrr
        1
    durrrr  
       2014-01-22 10:26:46 +08:00
    gmail 需要 ssl 吧

    stp = SMTP_SSL('smtp.gmail.com', 465)
    stp = smtplib.SMTP('smtp.gmail.com',587)
    o618
        2
    o618  
    OP
       2014-01-22 11:08:48 +08:00
    有可能,试试看
    66beta
        3
    66beta  
       2014-01-22 11:18:54 +08:00
    ssl要的,phpmailer就需要设置才通
    o618
        4
    o618  
    OP
       2014-01-22 11:49:04 +08:00
    @66beta 是用的python
    109109
        5
    109109  
       2014-01-22 12:44:22 +08:00   ❤️ 1
    109109
        7
    109109  
       2014-01-22 12:51:46 +08:00
    o618
        8
    o618  
    OP
       2014-01-22 13:01:34 +08:00
    @109109 赞,试试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   6302 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 01:53 · PVG 09:53 · LAX 18:53 · JFK 21:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.