Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker邮箱配置失效 #424

Closed
4 tasks done
MrLiuGangQiang opened this issue Jun 5, 2023 · 11 comments
Closed
4 tasks done

docker邮箱配置失效 #424

MrLiuGangQiang opened this issue Jun 5, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@MrLiuGangQiang
Copy link

Verify steps

  • Tracker 我已经在 Issue Tracker 中找过我要提出的问题
  • Latest 我已经使用 最新源码 测试过,问题依旧存在
  • Core 这是 QD 框架存在的问题,并非我所使用的 QD 早期版本(如 20210628及之前版号 等)或模板的特定问题
  • Meaningful 我提交的不是无意义的 催促更新或修复 请求

QD Version

20230601

Bug on OS

Linux

Bug on Platform

Docker/Linux 64位

To Reproduce

微信截图_20230605143618

Describe the Bug

image

QD config

No response

QD log

2023-06-05T06:28:10.053853327Z [I 230605 14:28:10 tornado.access web:2344] 200 POST /password_reset (222.210.139.25) 9.98ms
2023-06-05T06:28:10.053938102Z [I 230605 14:28:10 QD.Web.Handler login:252] password reset: userid=1 email=mrliugangqiang@vip.qq.com
2023-06-05T06:28:10.067027272Z [I 230605 14:28:10 QD.Http.Util utils:390] send mail to mrliugangqiang@vip.qq.com
2023-06-05T06:28:10.175999626Z [E 230605 14:28:10 QD.Http.Util utils:409] send mail error [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1002)
2023-06-05T06:28:40.821298357Z [I 230605 14:28:40 tornado.access web:2344] 302 POST /login (222.210.139.25) 110.19ms
2023-06-05T06:28:41.019646331Z [I 230605 14:28:41 tornado.access web:2344] 200 GET /my/ (222.210.139.25) 168.26ms
2023-06-05T06:28:45.627749660Z [I 230605 14:28:45 tornado.access web:2344] 304 GET /util/toolbox/1 (222.210.139.25) 7.66ms
2023-06-05T06:28:49.033169037Z [I 230605 14:28:49 tornado.access web:2344] 200 POST /util/urldecode (127.0.0.1) 0.83ms
2023-06-05T06:28:49.050955904Z [I 230605 14:28:49 tornado.access web:2344] 200 POST /task/17/run (222.210.139.25) 434.02ms
2023-06-05T06:28:49.060977730Z [I 230605 14:28:49 QD.Http.Util utils:390] send mail to mrliugangqiang@vip.qq.com
2023-06-05T06:28:49.166581933Z [E 230605 14:28:49 QD.Http.Util utils:409] send mail error [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1002)

Expected behavior

应该正常发出邮箱才对

Screenshots

No response

@MrLiuGangQiang MrLiuGangQiang added the bug Something isn't working label Jun 5, 2023
@a76yyyy
Copy link
Contributor

a76yyyy commented Jun 5, 2023

请检查你的邮箱配置中端口信息是否配置正确, 0601版本要求端口必须配置正确才可以;

如果还是有问题, 请发一下你的邮箱配置, 注意隐去隐私信息

@MrLiuGangQiang
Copy link
Author

请检查你的邮箱配置中端口信息是否配置正确, 0601版本要求端口必须配置正确才可以;

如果还是有问题, 请发一下你的邮箱配置, 注意隐去隐私信息

邮箱配置肯定是没有问题的 其他地方都在用这个

@MrLiuGangQiang
Copy link
Author

正确

我是用的QQ邮箱
SMTP:smtp.qq.com
PORT:587
账号密码可以肯定是没错的

@a76yyyy
Copy link
Contributor

a76yyyy commented Jun 6, 2023

正确

我是用的QQ邮箱 SMTP:smtp.qq.com PORT:587 账号密码可以肯定是没错的

端口号改成 465 试试

@hzfla
Copy link

hzfla commented Jun 7, 2023

端口改成25试试看,我用25端口可以正常使用,qq邮箱

@a76yyyy
Copy link
Contributor

a76yyyy commented Jun 13, 2023

SSL: WRONG_VERSION_NUMBER

参考 QQ邮箱 报错 SSL: WRONG_VERSION_NUMBER知乎
请修改邮箱端口 (QQ邮箱 一般开启SSL用465, 否则用25), 如果还有问题请 reopen 这个 Issue

@a76yyyy a76yyyy closed this as completed Jun 13, 2023
@liaojack8
Copy link

stmp port number587
需要先執行s.starttls()
後續login才不會出錯

if config.mail_ssl or config.mail_port in [465, 587]:

建議一下, 改為這樣應該就不會出錯, 實際QQ郵箱還需實測, 我用gmail沒問題

if config.mail_ssl or config.mail_port in [465, 587]:
                s = smtplib.SMTP_SSL(config.mail_smtp, config.mail_port)
                              if config.mail_port in 587: #use starttls
                                              s.starttls()

@liaojack8
Copy link

liaojack8 commented Feb 10, 2024

@a76yyyy 抱歉, 昨天發issue時miss掉了我這邊修改過的另外一個命令
starttls的連線方法順序為

s = smtplib.SMTP()
s.connect()
s.starttls()
s.login()
s.sendmail()
s.quit()

依照ˋ0859366
s.connect()s.starttls()方法順序顛倒不會直接報錯, 而是引發s.login()報錯
L463不會caught到err

logger_util.error("smtp starttls failed: %s", e, exc_info=config.traceback_print)

err msg 顯示send mail errror
2024-02-11_04h12_56

把465與587分成2個case處理應該還是比較好的, 這樣做就沒問題了
已經再三測試, 可以正常工作, 再次抱歉

async def _send_mail(to, subject, text=None, subtype='html'):
    if not config.mail_smtp:
        logger_util.info('no smtp')
        return
    msg = MIMEText(text, _subtype=subtype, _charset='utf-8')
    msg['Subject'] = subject
    msg['From'] = config.mail_from
    msg['To'] = to
    try:
        logger_util.info('send mail to %s', to)
        if config.mail_port:
            if config.mail_port == 465:
                s = smtplib.SMTP_SSL(config.mail_smtp, config.mail_port)
                s.connect(config.mail_smtp, config.mail_port)
            elif config.mail_port == 587: # use starttls
                s = smtplib.SMTP(config.mail_smtp, config.mail_port)
                s.connect(config.mail_smtp, config.mail_port)
                try:
                    s.starttls()
                except smtplib.SMTPException as e:
                    logger_util.error("smtp starttls failed: %s", e, exc_info=config.traceback_print)
        else:
            if config.mail_ssl:
                s = smtplib.SMTP_SSL(config.mail_smtp)
            else:
                s = smtplib.SMTP(config.mail_smtp)
            s.connect(config.mail_smtp)
        # s = config.mail_ssl and smtplib.SMTP_SSL(config.mail_smtp) or smtplib.SMTP(config.mail_smtp)
        if config.mail_user:
            s.login(config.mail_user, config.mail_password)
        s.sendmail(config.mail_from, to, msg.as_string())
        s.close()
    except Exception as e:
        logger_util.error('send mail error: %s', e, exc_info=config.traceback_print)
    return

@liaojack8
Copy link

另外我寫了一個測試starttls連線寄信的小程式
使用starttls連線的朋友可以先測試看看, 能成功寄送的話
這次bug修復掉, 發版過後, 郵箱配置應該就沒問題了

@a76yyyy 也許可以考慮一下要不要把starttls另外加到config選項中
好像有遇過少數部分郵箱服務使用starttls協議但default port不是587的
未來應該也會漸漸全面改用starttls, 這部分outlook領先
可以看到微軟幫助已經全面拿掉SSL, 只剩下TLS與STARTTLS

import smtplib
from email.mime.text import MIMEText

def send_email_starttls(smtp_server, smtp_server_port, sender, password, receiver, message):
    server = smtplib.SMTP(smtp_server,smtp_server_port)
    server.connect(smtp_server, smtp_server_port)
    smtp_ttls = server.starttls()
    print(f'start tls ==> {smtp_ttls}')

    server.login(sender, password)
    message['From'] = sender
    status = server.sendmail(sender, receiver, message.as_string())
    if not status:
        print('寄信成功')
    else:
        print(f'寄信失敗。{status}')
      
    server.quit()

if __name__ == '__main__':
    smtp_server = 'smtp-mail.outlook.com'
    smtp_server_port = 587
    sender_address = 'xxxxxxxx@outlook.com'
    sender_password = 'xxxxxxxx'
    to_mail = 'Your emil address'

    message = MIMEText(_text = 'Are all settings correct?\r\nSent via mail.py')
    message['Subject'] = 'Test Message'
    message['To'] = to_mail
    send_email_starttls(smtp_server, smtp_server_port, sender_address, sender_password, to_mail, message)

@a76yyyy
Copy link
Contributor

a76yyyy commented Feb 11, 2024

另外我寫了一個測試starttls連線寄信的小程式
使用starttls連線的朋友可以先測試看看, 能成功寄送的話
這次bug修復掉, 發版過後, 郵箱配置應該就沒問題了

@a76yyyy 也許可以考慮一下要不要把starttls另外加到config選項中
好像有遇過少數部分郵箱服務使用starttls協議但default port不是587的
未來應該也會漸漸全面改用starttls, 這部分outlook領先
可以看到微軟幫助已經全面拿掉SSL, 只剩下TLS與STARTTLS

@liaojack8 建议开一个PR吧,在PR中共同审查代码

@fgrtew
Copy link

fgrtew commented Jun 19, 2024

创建容器的时候提示:Create container qd-1 failed: {"message":"No command specified"}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants