Sending Mail from @qq.com

从emacs中设置发送邮件的功能(只需要发送邮件这一个功能)

亦步亦趋按照Sending Mail wiki, 如下设置.

;;Email

(setq user-mail-address "[email protected]")
(setq user-full-name "abst.proc.do")

(require 'smtpmail)
(require 'starttls)

(setq message-send-mail-function 'smtpmail-send-it)
(defun gnutls-available-p ()
  "Function redefined in order not to use built-in GnuTLS support"
  nil)
(setq smtpmail-debug-info t)
(setq smtpmail-debug-verb t)
(setq starttls-gnutls-program "gnutls-cli")
(setq starttls-use-gnutls t)
(setq smtpmail-stream-type 'starttls)
(setq smtpmail-smtp-server "smtp.qq.com")
(setq smtpmail-smtp-service 587) ;;587(starttls) or 465(tls/ssl)
(setq gnutls-algorithm-priority "NORMAL:%COMPAT")
;;(setq starttls-extra-arguments '("--priority" "NORMAL:%COMPAT"))

(provide 'email)

配置 .authinfo

machine smtp.qq.com login [email protected] password fbgnswlulxy***

qq-mail中POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务全部已经打开, 并且设置thundermail正常工作.

但是从emacs中发送邮件不成功

From: [email protected] (abst.proc.do)
To: [email protected]
Subject: Testing
Date: Sat, 01 Feb 2020 20:57:53 +0800
Message-ID: <[email protected]>
--text follows this line--
Testing

提示unsend mail, mini-buffer中停留在:

Opening STARTTLS connection to ‘smtp.qq.com:587’...

Trace buffer中的信息

220 newxmesmtplogicsvrsza2.qq.com XMail Esmtp QQ Mail Server.
250-newxmesmtplogicsvrsza2.qq.com
250-PIPELINING
250-SIZE 73400320
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN
250-MAILCOMPRESS
250 8BITMIME
\0\0\0k\0\0\0[\0\0\0\0\0\0\0502 Timeout from 2408:84e1:129:4a89:44cf:ea80:2294:c6cc to newxmesmtplogicsvrsza2.qq.com.
*** Fatal error: The TLS connection was non-properly terminated.
*** Server has terminated the connection abnormally.

Process smtpmail exited abnormally with code 1

Process smtpmail<1> deleted
220 newxmesmtplogicsvrsza3.qq.com XMail Esmtp QQ Mail Server.
250-newxmesmtplogicsvrsza3.qq.com
250-PIPELINING
250-SIZE 73400320
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN
250-MAILCOMPRESS
250 8BITMIME
220 Ready to start TLS from 2408:84e1:129:4a89:44cf:ea80:2294:c6cc to newxmesmtplogicsvrsza3.qq.com.
*** Starting TLS handshake
- Certificate type: X.509
- Got a certificate list of 3 certificates.
- Certificate[0] info:
 - subject `CN=*.mail.qq.com,O=Tencent Technology (Shenzhen) Company Limited,L=shenzhen,ST=guangdong,C=CN', issuer `CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE', serial 0x41110235e23a37f3ead2dc5e, RSA key 2048 bits, signed using RSA-SHA256, activated `2019-11-11 10:32:16 UTC', expires `2020-06-03 04:00:33 UTC', pin-sha256="3gHtBaJCDCS2wo6ho7kKEE6rUA1YXM3A6R1XiFejm48="
	Public Key ID:
		sha1:5df67c6c87174f49828307072b0922d6da77cab0
		sha256:de01ed05a2420c24b6c28ea1a3b90a104eab500d585ccdc0e91d578857a39b8f
	Public Key PIN:
		pin-sha256:3gHtBaJCDCS2wo6ho7kKEE6rUA1YXM3A6R1XiFejm48=

- Certificate[1] info:
 - subject `CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE', issuer `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', serial 0x040000000001444ef04247, RSA key 2048 bits, signed using RSA-SHA256, activated `2014-02-20 10:00:00 UTC', expires `2024-02-20 10:00:00 UTC', pin-sha256="IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4="
- Certificate[2] info:
 - subject `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', issuer `CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE', serial 0x040000000001154b5ac394, RSA key 2048 bits, signed using RSA-SHA1 (broken!), activated `1998-09-01 12:00:00 UTC', expires `2028-01-28 12:00:00 UTC', pin-sha256="K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q="
- Status: The certificate is trusted. 
- Description: (TLS1.2)-(ECDHE-SECP256R1)-(RSA-SHA512)-(AES-128-GCM)
- Session ID: 13:F1:61:99:B6:F1:8B:13:09:48:BD:F4:FE:19:9F:FA:EB:9F:43:49:CB:04:09:4D:0A:CC:F1:43:98:28:CE:62
- Options: safe renegotiation,
\0\0\0k\0\0\0[\0\0\0\0\0\0\0502 Timeout from 2408:84e1:129:4a89:44cf:ea80:2294:c6cc to newxmesmtplogicsvrsza3.qq.com.
*** Fatal error: The TLS connection was non-properly terminated.
*** Server has terminated the connection abnormally.

Process smtpmail<1> exited abnormally with code 1

哪里的设置有问题呢?

没这么多设置吧?发邮件只需 SMTP,写好 SMTP 账户信息(地址、账户、密码)就完了。

我试了下,需要先到设置-账户底下开启 SMTP,获得登陆密码,然后填好账户、SMTP 地址:

(setq smtpmail-smtp-user "[email protected]"
      smtpmail-smtp-server "smtp.qq.com"
      smtpmail-smtp-service 465
      smtpmail-stream-type 'ssl)

密码:

machine smtp.qq.com login [email protected] password qacuydgpshdbgbzn

然后 C-x m (compose-mail) 就能发邮件了。

3 个赞

正解~~~~

重新设置: ;;Email

(setq user-mail-address "[email protected]")
(setq user-full-name "abst.proc.do")

(setq smtpmail-smtp-user "[email protected]"
      smtpmail-smtp-server "smtp.qq.com"
      smtpmail-smtp-service 465
      smtpmail-stream-type 'ssl)

(provide 'email)

从qq的stmp中生成授权码

设置authinfo

$ cat ~/.authinfo
machine smtp.qq.com  login [email protected] password  nivfom........e

报错:

Sending via mail...
smtpmail-send-it: Sending failed: 503 Error: need EHLO and AUTH first !

重启了两次emacs, 同样的报错,

尝试用邮箱的登录密码替换授权码, 重启emacs发送邮件, 相同的报错.

GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.11) of 2019-09-23, modified by Debian

我的emacs是不是读不到".authinfo"? 怎么核实?

你先看下 auth-sources 是啥。


Tips: 换别的吧,我推荐 mutt。

(auth-source-search :host "smtp.qq.com")
;; => ((:host "smtp.qq.com" :user "[email protected]" :secret #[... ...] 3]))

如果刚刚编辑过 .authinfo,需要更新缓存的话,M-x auth-source-forget-all-cached

1 个赞

真不容易, doom-emacs改了auth-sources,

花了一天时间读完文档才功能正常.

https://www.gnu.org/software/emacs/manual/html_node/auth/index.html

https://www.gnu.org/software/emacs/manual/html_node/smtpmail/index.html#Top

(require 'auth-source);; probably not necessary
(setq auth-sources '("~/.authinfo" "~/.authinfo.gpg"))
;;(customize-variable 'auth-sources) ;; optional, do it once

(setq message-send-mail-function 'smtpmail-send-it)
(setq smtpmail-debug-info t)
(setq smtpmail-debug-verb t)


(setq user-mail-address "[email protected]")
(setq user-full-name "abst.proc.do")

(setq smtpmail-smtp-user "[email protected]"
      smtpmail-smtp-server "smtp.qq.com"
      smtpmail-smtp-service 465
      smtpmail-stream-type 'ssl)

Sending…done