启动一个本地 SMTP Server,为了测试:
~ $ python3 -m smtpd -c DebuggingServer -n localhost:1025
发送邮件:
(require 'smtpmail)
(with-temp-buffer
(insert "To: [email protected]\n"
"From: [email protected]\n"
"\n"
"GOOD NIGHT.\n")
(let ((smtpmail-smtp-server "localhost")
(smtpmail-smtp-service 1025)
(smtpmail-stream-type nil))
(smtpmail-via-smtp '("[email protected]") (current-buffer))))
本地 SMTP Server 会显示发送成功:
~ $ python3 -m smtpd -c DebuggingServer -n localhost:1025
---------- MESSAGE FOLLOWS ----------
b'To: [email protected]'
b'From: [email protected]'
b'X-Peer: ::1'
b''
b'GOOD NIGHT.'
------------ END MESSAGE ------------
用一个真实的 SMTP Server。由于 SMTP 的密码貌似必须写到 ~/.authinfo
中(比如可惜):
machine smtp.fastmail.com login [email protected] password xxxxxxxxx
发送邮件:
(let ((smtpmail-smtp-server "smtp.fastmail.com")
(smtpmail-smtp-service 465)
(smtpmail-stream-type 'ssl))
(with-temp-buffer
(insert "To: [email protected]\n"
"From: [email protected]\n"
"\n"
"GOOD NIGHT.\n")
(smtpmail-via-smtp '("[email protected]") (current-buffer))))
检查邮箱,发送成功。