簡體   English   中英

GNU通過同一服務器向多個外發帳戶發送電子郵件而不使用imap

[英]GNUs email multiple outgoing accounts from the same server without imap

我使用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

消息模式的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

我有一個類似的設置,我在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

但我切換到使用postfix發送郵件。 您可以做的是設置postfix,以便它(例如)可以接收USER1 @ gmail.com,USER2 @ gmail.com,USER3 @ googlehosteddomain.com的郵件並將所有郵件發送到smtp.gmail.com ,同時使用適當的每種情況下的帳戶憑據。 這要求您安裝Postfix程序,並設置文件* / etc / postfix / sasl_passwd *和* / etc / postfix / sender_relay *。

我在同一個郵件服務器上有多個SMTP帳戶,只需為每個郵件帳戶定義一個具有不同“域”的主機文件條目。

我認為更好的解決方案是將所有smtp auth詳細信息放在~/.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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM