unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Teemu Likonen <tlikonen@iki.fi>
To: Marius Hofert <marius.hofert@math.ethz.ch>
Cc: Emacs help <help-gnu-emacs@gnu.org>
Subject: Re: Gnus: How to easily change "From:" from the default to a second account's address?
Date: Sat, 03 Dec 2011 21:17:37 +0200	[thread overview]
Message-ID: <87mxb9o46m.fsf@mithlond.arda> (raw)
In-Reply-To: <812215ED-D638-4BE4-8AD3-AC7EB95378E0@math.ethz.ch> (Marius Hofert's message of "Wed, 23 Nov 2011 17:24:49 +0100")

* 2011-11-23T17:24:49+01:00 * Marius Hofert wrote:

> If I want to create a new message with "m", it shows my default email
> address in "From:" [...] every once in a while I would like to hav
> "From: my.name@googlemail.com" instead of "From: my.name@uni.edu". So
> far, I deleted the entry and typed in my gmail account's address. Is
> there a simpler way?

Here's my solution for (1) setting up Gnus for several mail addresses
and (2) cycling them easily in a message-mode buffer (using F9 key).


    (setq user-full-name "User Name")

    (defvar my-email-addresses
      '("primary.address@internet.invalid"
        "other.address@somewhere.invalid"
        "yet.another@invalid"))

    ;; Set important variables

    (let ((addr my-email-addresses))
      (setq-default
       user-mail-address (car addr)
       message-alternative-emails (regexp-opt (cdr addr) 'words)
       message-dont-reply-to-names (regexp-opt addr 'words)
       gnus-ignored-from-addresses message-dont-reply-to-names))

    ;; The cycling functionality
    
    (add-hook 'message-mode-hook 'my-message-mode-hook)

    (defun my-message-mode-hook ()
      (define-key message-mode-map (kbd "<f9>")
        'my-message-toggle-from))

    (defun my-message-toggle-from ()
      (interactive)
      (require 'mail-extr)
      (let* ((current (nth 1 (mail-extract-address-components
                              (message-fetch-field "From"))))
             (next (or (nth 1 (member current my-email-addresses))
                       (nth 0 my-email-addresses))))

        (when (and current next)
          (save-excursion
            (save-restriction
              (message-narrow-to-head)
              (save-match-data
                (when (re-search-forward "^From: " nil t)
                  (message-narrow-to-field)
                  (delete-region (point-min) (point-max))
                  (insert "From: " user-full-name " <" next ">\n"))))))))



      parent reply	other threads:[~2011-12-03 19:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-23 16:24 Gnus: How to easily change "From:" from the default to a second account's address? Marius Hofert
2011-11-23 16:35 ` Tassilo Horn
2011-11-23 22:17   ` Marius Hofert
2011-11-25  2:17     ` Philipp Haselwarter
2011-11-25  3:12       ` Eric Abrahamsen
2011-11-26 12:03         ` Philipp Haselwarter
2011-11-27  1:52           ` Eric Abrahamsen
2011-12-03 21:10             ` Johnny
2011-12-03 22:53               ` Philipp Haselwarter
2011-12-04 12:58                 ` Harry Putnam
2011-12-05 19:44                   ` Richard Riley
2011-12-05 20:18                     ` Johnny
2011-12-05 20:39                       ` Richard Riley
2011-12-05 20:58                         ` Johnny
2011-11-27 19:03 ` Memnon Anon
2011-12-03 19:17 ` Teemu Likonen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mxb9o46m.fsf@mithlond.arda \
    --to=tlikonen@iki.fi \
    --cc=help-gnu-emacs@gnu.org \
    --cc=marius.hofert@math.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).