4

我使用 GNU 和多个电子邮件地址,包括根据消息上的 FROM 更改传出 SMTP。到目前为止,一切都很好。不过,现在我在同一台服务器上有多个帐户,所以通常的 .authinfo 对我不起作用。似乎答案应该类似于http://www.cataclysmicmutation.com/2010/11/multiple-gmail-accounts-in-gnus/ 但我没有使用 gmail,也没有使用 imap。我正在使用 SMTP 和 SSL。如何扩展该解决方案?(另外:我正在使用 gnus-posting-styles 来帮助发送具有适当地址的邮件,这是值得的)

以下是我的 .gnus 的相关部分。请注意,我试图让 webdev@[ME].com 正常工作,这是 [ME]@[ME].com (都是同一台服务器)的补充。我在这里和我的 authinfo 中需要什么来完成这项工作?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; multiple outgoing accounts ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://www.mostlymaths.net/2010/12/emacs-30-day-challenge-using-gnus-to.html
;; also see ~/.authinfo
(defvar smtp-accounts
  '(
    (ssl "[ME]@[ME].com" "mail.[ME].com"
     26 "[ME]@[ME].com" secret)
    ;; (ssl "webdev@[ME].com" "mail.[ME].com"
    ;;   26 "webdev@[ME].com" secret)
    (ssl "[ME]@gmail.com" "smtp.gmail.com"
     587 "[ME]@gmail.com" secret)
    (ssl "[ME]@gatech.edu" "mail.gatech.edu"
          587 "[ME]@gatech.edu" secret)
    ))

;; Now lets configure smtpmail.el with your name and functions to send
;; mail using your smtp accounts by changing the from field
(require 'smtpmail)
(setq send-mail-function 'smtpmail-send-it
      message-send-mail-function 'smtpmail-send-it
      mail-from-style nil user-full-name "[ME] S. "
      smtpmail-debug-info t smtpmail-debug-verb t)

(defun set-smtp (mech server port user password)
  "Set related SMTP variables for supplied parameters."
  (setq smtpmail-smtp-server server smtpmail-smtp-service port
    smtpmail-auth-credentials (list (list server port user
                          password)) smtpmail-auth-supported (list mech)
                          smtpmail-starttls-credentials nil)
  (message "Setting SMTP server to `%s:%s' for user `%s'."
       server port user))

(defun set-smtp-ssl (server port user password &optional key
                cert)
  "Set related SMTP and SSL variables for supplied parameters."
  (setq starttls-use-gnutls t
    starttls-gnutls-program "gnutls-cli"
    starttls-extra-arguments nil smtpmail-smtp-server server
    smtpmail-smtp-service port
    smtpmail-auth-credentials (list (list server port user
                          password)) smtpmail-starttls-credentials (list (list
                                                  server port key cert)))
  (message
   "Setting SMTP server to `%s:%s' for user `%s'. (SSL
enabled.)" server port user))

(defun change-smtp ()
  "Change the SMTP server according to the current from line."
  (save-excursion
    (loop with from = (save-restriction
            (message-narrow-to-headers)
            (message-fetch-field "from"))
      for (auth-mech address . auth-spec) in smtp-accounts
      when (string-match address from) do (cond
                           ((memq auth-mech '(cram-md5 plain login))
                        (return (apply 'set-smtp (cons auth-mech auth-spec))))
                           ((eql auth-mech 'ssl)
                        (return (apply 'set-smtp-ssl auth-spec)))
                           (t (error "Unrecognized SMTP auth. mechanism:
`%s'." auth-mech))) finally (error "Cannot infer SMTP information."))))

;; The previous function will complain if you fill the from field with
;; an account not present in smtp-accounts.

(defvar %smtpmail-via-smtp (symbol-function 'smtpmail-via-smtp))

(defun smtpmail-via-smtp (recipient smtpmail-text-buffer)
  (with-current-buffer smtpmail-text-buffer
    (change-smtp))
  (funcall (symbol-value '%smtpmail-via-smtp) recipient
       smtpmail-text-buffer))

;; This wraps send mail via smtp mail, to be able to send multiple
;; messages with smtpmail.

;; Reply-to with same address it was sent to
    (setq gnus-posting-styles
      '(((header "to" "[ME]@gmail.com")
         (address "[ME]@gmail.com"))
    ((header "to" "[ME]@gatech.edu")
         (address "[ME]@gatech.edu"))
    ((header "to" "[ME]@[ME].com")
         (address "[ME]@[ME].com"))
    ;; ((header "to" "webdev@[ME].com")
        ;;  (address "webdev@[ME].com"))
    ;; ((header "cc" "webdev@[ME].com")
        ;;  (address "webdev@[ME].com"))
    ((header "cc" "[ME]@[ME].com")
         (address "[ME]@[ME].com"))
    ((header "cc" "[ME]@gatech.edu")
         (address "[ME]@gatech.edu"))
    ((header "cc" "[ME]@gmail.com")
         (address "[ME]@gmail.com"))))

解决方案

我正在寻找的答案如下。为了完整起见,我将使用我的 /etc/host 文件、.authinfo 和 .gnus 发布我的最终解决方案。

;; excerpt from .gnus
(defvar smtp-accounts
  '(
    (ssl "first@onedomain.com" "mail.onedomain.com"
     26 "first@onedomain.com" secret)
    (ssl "second@onedomain.com" "mail.onedomain2.com" ;; <-- This is the new alias in my /etc/hosts
         26 "username@onedomain.com" secret) ;; <-- Added these two lines
    ))

;; excerpt from .authinfo
machine mail.onedomain.com login username@onedomain.com port 26 password MyPASS
machine mail.onedomain2.com login username@onedomain.com port 26 password "MyOtherPASS"

;; excerpt from /etc/hosts. The IP was obtained by pinging my mail.onedomain.com
69.89.31.60 mail.onedomain2.com onedomain2
4

4 回答 4

7

消息模式的 X-Message-SMTP-Method 标头字段也可能有所帮助。

例子:

X-Message-SMTP-Method: smtp smtp.fsf.org 587 other-user

更多信息:

  1. https://www.gnu.org/software/emacs/manual/html_node/message/Mail-Variables.html
  2. https://www.gnu.org/software/emacs/manual/html_node/gnus/Posting-Styles.html
于 2014-04-03T20:10:03.660 回答
2

我有一个类似的设置,我使用 gnus 中的发布样式在多个电子邮件帐户之间进行选择。我曾经像提到的那样做,为同一主机定义不同的别名,具有 authinfo 条目。它看起来像这样:

Contents of ~/.authinfo.gpg:
machine imap.gmail-alias1.com login me@hosteddomain.org password pass port 993
machine imap.gmail-alias2.com login me@gmail.com password pass port 993
machine smtp.gmail1.com login me@hosteddomain.org port 587 password
machine smtp.gmail2.com login me@gmail.com port 587 password

Partial contents of /etc/hosts:
# So I can use multiple gmail accounts in authinfo
# should be same address as imap.gmail.com
173.194.70.108 imap.gmail-alias1.com
173.194.70.108 imap.gmail-alias2.com

74.125.136.108 smtp.gmail1.com
74.125.136.108 smtp.gmail2.com

但是我改用后缀来发送邮件。您可以做的是设置后缀,以便它可以(例如)接收 USER1@gmail.com、USER2@gmail.com、USER3@googlehosteddomain.com 的邮件并将所有邮件发送到smtp.gmail.com,同时使用适当的每种情况下的帐户凭据。这需要您安装Postfix程序,并设置文件 */etc/postfix/sasl_passwd* 和 */etc/postfix/sender_relay*。

于 2014-01-10T04:33:10.610 回答
0

我在同一邮件服务器上有多个 SMTP 帐户,只需为每个邮件帐户定义一个具有不同“域”的主机文件条目。

于 2014-01-06T14:41:07.247 回答
0

我认为更好的解决方案是将所有 smtp 身份验证详细信息放入~/.authinfo.gpg并(重新)设置smtpmail-smtp-user为您要从中发送的用户帐户。smtpmail.el 然后将使用此条目的密码,即使同一服务器有多个条目。来自smtpmail.el

(defcustom smtpmail-smtp-user nil
  "User name to use when looking up credentials in the authinfo file.
If non-nil, only consider credentials for the specified user."
  :version "24.1"
  :type '(choice (const nil) string)
  :group 'smtpmail)
于 2016-03-27T00:14:37.293 回答