>>>> "Neal" == Neal D Becker
<nbecker(a)hns.com> writes:
>>>>> "APA" == Adrian Aichner <Adrian.Aichner(a)t-online.de>
writes:
>>>> "Neal" == Neal D Becker
<nbecker(a)hns.com> writes:
Neal> This must be a fairly common requirement.
I wonder how others address
Neal> it.
Neal> When sending mail withing my local organization I want my From header
Neal> to say one thing, but for external mail I'd like it to say something
Neal> else. I wish there was some quick way for me to switch back and
Neal> forth. What do other people do?
I had this same problem, more or less.
Here's what I did to solve it: I have a mail-send-hook (and message-send-hook,
same function) that puts up a prompt for a single letter input that indicates
how I wish to send the email (I use smtpmail, by the way) that then calls
functions that set up the smtpmail settings appropriately (I sometimes need to
go through a different mail sever) as well as changing the variable
user-mail-address, which sets the From header appropriately.
Here's a trimmed down version of the code I use with the names changed to
protect the perhaps-not-so-innocent:
======================================================================
(defun my-mail-send-hook ()
(interactive)
(let ((k ""))
(while (equal k "")
(progn
(message "Send via (l)ocal, e(x)ternal1, or external(2)? ")
(setq k (read-char-exclusive))
; char-equal should be case insensitive, since case-fold-search
; should be t
(if (not (cond
((or (char-equal k ?l)) (progn (smtp-via-local)))
((or (char-equal k ?x)) (progn (smtp-via-external1)))
((or (char-equal k ?2)) (progn (smtp-via-external2)))
)
)
(progn
(beep)
(setq k ""))
)))))
(add-hook 'mail-send-hook 'my-mail-send-hook)
(add-hook 'message-send-hook 'my-mail-send-hook)
(defun smtp-via-local ()
(interactive)
(message "initializing smtpmail for local domain")
(sit-for 0.5)
;;(setq user-mail-address (concat (user-login-name) "@" (system-name)))
;; something is messed up on my machine, so I need this:
(setq user-mail-address "me(a)localdomain.com")
;;(setq smtpmail-smtp-server "localhost") ;; localhost didn't work???
(setq smtpmail-smtp-server (system-name))
)
(defun smtp-via-external1 ()
(interactive)
(message "initializing smtpmail for external1 settings")
(sit-for 0.5)
(setq user-mail-address "me(a)extern1domain.com")
;; for now, simply use localhost for sending, should be fine
(setq smtpmail-smtp-server "smtp.external1domain.com")
)
(defun smtp-via-external2 ()
(interactive)
(message "initializing smtpmail for external2 settings")
(sit-for 0.5)
(setq user-mail-address "me(a)external2domain.com")
(setq smtpmail-smtp-server "smtp.external2domain.com")
)
======================================================================
Of course, you could simply use the same (local?) smtp server for all 3 if it
allows you to change the From addresses with impunity (which is what I do
right now but have had different ones in the past).
I'm sure the code could be further simplified, but I wrote it a long time ago
and haven't really had the urge to go back and clean it up more since it's
worked fine for me as is.
APA> Hi Neal,
APA> See
APA> C-h C-i g n u s RET i p o s t i n g SPC s t y l e RET
APA> This is what I use.
APA> The problem I have is that my ISP (t-online.de) does not let me set my
>> From header to a separate domain (adrian(a)xemacs.org).
APA> I guess it makes sense from their point of view :-)
APA> Is there a solution for this as well?
Neal> Set a Reply-to header? That's actually what I wanted to do.
If you wanted to do something similar to my approach above with Reply-To,
you'd probably have to look at the code in smtpmail.el where it adds the From
header as needed and replicate that in the mail-send-hook for adding the
Reply-To yourself since smtpmail doesn't do it for you (it's only about 44
lines of elisp, search for "odd reason" to find it, it's in
smtpmail-send-it).
Hope this helps,
Chuck
--
Charles K. Hines <ckh(a)requesttech.com> <chuck.hines(a)baesystems.com>
Principal Scientist at ReQuest Technologies Inc (
http://www.ReQuestTech.com/)
"You tell him and I will smack you. I will smack you like a
bad bad donkey, okay!" - Pepe in 'Muppets From Space'