Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Mutt made easy : multiple accounts
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Qubax
Guru
Guru


Joined: 19 Jul 2002
Posts: 451
Location: Tirol, Austria

PostPosted: Tue May 11, 2004 7:03 pm    Post subject: Mutt made easy : multiple accounts Reply with quote

Mutt made easy: multiple accounts

For sure there are errors and other things wrong down
there. Nobody's perfect.

started: 11/05/04
update: 15.07/04 (minor fixes and changes to follow docu-guideline, added Appendix B)

So you're, like me, one of those, you like to use
console-programs. You heard of mutt but all the things you need
to do, just for getting an email... And afterwards a lot of
configuration for sending ...

First of all:

~~~

This is meant to explain how to use mutt with multiple
email accounts on different servers. In my case, these are all
pop3 servers. This is written for 2 accounts: name1@isp1 and
name2@isp2, but more accounts can easily be added.

I don't provide information for setting up an
email server. That's not needed for mutt.

I explain this using ordinary free email-accounts like gmx,
hotmail etc.

~~~

For those of you who would like to know why I don't want to set
up a server:

First of all: My box is not running 24/7. My provider disconnects
my adsl-line every 8 hours. Sometimes (especially summer ->
thunder storms) they have problems, so 2-3 days without internet are
not unusual. Nobody could send emails to my server, if I'd use
my own one on this box.

As I understand things, it should not be that hard to set up an
email server. But many email services block emails from mail servers
without a registered domain, because they could just be set up for
spamming our mailboxes. Somewhere I read about registering at
dyndns, ... but that goes beyond the scope of this document.

~~~

I searched and found programs for fetching (getmail) and
sending (msmtp) emails that are really easy to configure. All
you need is the information you would give your gui-mailreader -
servername, username, password.

In the beginning, i'm not discussing filtering. But you'll find the
modifications at the bottom.

Code:

emerge getmail mutt msmtp


At the moment, msmtp is not included in portage, but you can download
the ebuild here
https://bugs.gentoo.org/show_bug.cgi?id=33423. Just put it
into your portdir-overlay (how, where etc -> not discussed here)

UPDATE: msmtp is now in portage. No "problems" any more at this point

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  1. Basics:

    For configuring mutt we are going to use the default .muttrc in
    your $HOME. Further options are going into files
    located in ~/.mutt/ , and we'll include them with a single line in
    .muttrc.

    Mail will be saved in ~/.muttmail/

    Cause we are not going to filter the email, we are going to
    transfer it directly into the mailboxes, called box1 for our
    isp1 account and box2 for our isp2 account. These are located in
    ~/.muttmail/

    These mailboxes should be in maildir format. Pro and cons you can
    read everywhere.

    How to make a maildir-format mailbox? All you need to do, is
    create 3 folders called "new,cur,tmp" in the mailbox directory.

    Code:

    mkdir -p ~/.muttmail/box{1,2}/{new,cur,tmp}


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  2. Fetching emails:

    Now we have the mailboxes. So let's try to fetch some emails.
    For this we are going to use getmail.

    Now create a getmail home-directory
    Code:

    mkdir ~/.getmail


    Then copy the example rc-file from /usr/doc/getmail-3.1.7/ to the
    getmail home-directory

    Code:

    cp /usr/doc/getmail-3.1.7/getmailrc-example.gz ~/.getmail/


    Unpack it and have a look with your preferred editor. I won't
    discuss everything, because the comments should explain everything.

    Now let us make our own rc-file. it should look like this:

    Code:

    [default]                                       # This section provides default arguments and values,
                                                    #    and variables which can be used in other sections
    verbose = 1                                     # Be verbose by default
    readall = 0                                     # Retrieve only new messages by default
    delete = 1                                      # Delete mail after retrieval by default
    message_log = /var/log/getmail.log              # Log message retrieval and delivery to this file by default
    timeout = 240                                   # TCP timeout value; increase if on a poor connection or
                                                    #    slow POP3 server.  getmail defaults to a 180 second timeout.
    max_message_size = 0                            # Default is 0, which means no limit.

    [isp1's mail]                                    # Simple configuration for a single-user POP3 mailbox
    server = mail.isp1.net
    username = username1@isp1
    password = passwd1
                                                    # if no password specified prompt for it when getmail is run
    use_apop = 0                                    # Use APOP authentication for this account instead of
                                                    #   cleartext PASS
    postmaster = ~/.muttmail/box1/                  # Default delivery to this Maildir
    message_log = ""                                # Don't log for this account
                                                    # No "local" directives necessary.
    no_delivered_to = 1                             # Don't add a Delivered-To: header for this mailbox
    no_received = 1                                 # Don't add a Received: header for this mailbox

    [isp2's mail]
    server   = mail.isp2.net
    username = username2@isp2
    password = passwd2
    use_apop = 0

    postmaster = ~/.muttmail/box2/

    message_log = ""
    no_delivered_to = 1
    no_received = 1


    Just edit servers, usernames and passwords according to our
    email provider.

    If everything is correct, execute getmail in a terminal, and it
    should look for emails and deliver them to box1 or box2,
    depending which isp it came from.

    That's it.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  3. Viewing emails:

    If you start mutt, nothing important will happen. First you have to
    tell it where to look for email. So we are going through
    some really basic settings in your .muttrc, so you can have a look at
    your emails.

    Make a .muttrc file in your home directory and add the following
    settings to it:

    Code:

    # folder where = refers to
    set folder=~/.muttmail

    # you would take the dir, where all the unfiltered mail drops in as
    # spoolfile
    # cause we transfer the mail for different  accounts direct into the
    # mailboxes, you can take one of them. it's just the "starting-folder"
    set spoolfile=~/.muttmail/box1

    # tell him, that there are 2 mailboxes, called box1 and box2
    # = refers to $folder
    mailboxes =box1
    mailboxes =box2


    That's it. Start mutt. Type "c" for changing to a folder, press "?" to
    see what's possible. At this point you should see box1 and box2. Move
    to them, press enter and so on.

    If you have mails in there, you should see them now. Nothing more to
    do at this point.

    Ok, one more point. Every time you want to check for new email, you
    have to open a console and start getmail. Not what we want. So we
    define a keybinding, so that mutt executes getmail in a subshell. For
    this just add the following to your .muttrc

    Code:

    # to start getmail without pressing enter i add <enter> after getmail.
    # (for "yes-this command")
    macro index g "!getmail<enter>" 'start getmail'


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Now comes the only "difficult" part:
    composing and sending emails

    I just copied the part out of my .muttrc, cause I think it's
    self-explaining

    Code:

    # use your preferred editor for writing emails
    set editor=emacsclient

    # start editor without asking for to, subject,...
    set autoedit

    # cause we put headers in editor when composing messages
    set edit_headers


    Now start mutt and try to compose a message. Just save it and exit
    your editor afterwards, then you'll get back to mutt. Everything looks
    good, but at this point mutt doesn't know how to send mail.

    So have a look in the man pages of msmtp. You will see that
    all you have to do, is to create a .msmtprc file in your home
    dir, including this:

    Code:

    account isp1
    host mail.isp1.net
    from name1@isp1.net
    user username1@isp1
    password password1


    account isp2
    host mail.isp2.net
    from name2@isp2.net
    user username2@isp2
    password password2


    So, that should be everthing. Now we have to tell mutt, which
    sendmail-command to use.

    My idea: Define a keybinding, that tells mutt which sendmail-prog it
    should use, and tell me which I've set.

    So add these lines to your .muttrc:

    Code:

    # after writing the email you can switch for different email-accounts
    # don't linebreak macros
    macro compose "\ca1" ':set sendmail="/usr/bin/msmtp --account isp1"<enter>;:set compose_format="ISP1 -- Mutt: Compose [Approx. msg size: %l Atts: %a]%>-"<enter>' 'use isp1-account'
    macro compose "\ca2" ':set sendmail="/usr/bin/msmtp --account isp2"<enter>;:set compose_format="ISP" -- Mutt: Compose [Approx. msg size: %l Atts: %a]%>-"<enter>' 'use isp2-account'


    After composing an email, you can press "ctrl+a 1" for setting
    sendmail according to isp1, or with "ctrl+a 2" for isp2.

    This should be all.
    Finished.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Appendix A:

You're right. Not finished.

We want mail-filtering (me hates spam). So we've to include some prog,
to do this. Procmail seems to be commonly used. So let's try it out...

Code:

emerge -pu procmail

-> ssmtp, procmail


Why ssmtp? Cause procmail want's to install the "virtual/mta". So
let's have a look in /var/cache/edb/virtuals. Somewhere you'll find
Code:

virtual/mta net-mail/ssmtp


i don't really know, what i'm doing, but i don't want to install ssmtp
and i (for the moment) know, that procmail won't have to send an
email. So i change the virtual from ssmtp to msmtp.

Code:

emerge -pu procmail
-> procmail


So, what to do next? Just emerge procmail. It will ask you for a mta,
i just inserted msmtp. Maybe i've to correct something here later on.

procmail is now avaible.

Have a look in the procmailrc-file. It want's your MAILDIR defined, so
he knows, where the mailboxes are located. In our case this is equal
to ~/.muttmail.

And he wants a default box, where he should put unfiltered mail
to. But we have two accounts. For each, the filtering rules should
apply, but the unfiltered mails should not all drop in the same box,
we want unfiltered mail from isp1 to destinate in box1 and unfiltered
mail from isp2 to drop in box2. So we are going to tell procmail which
default he should use in the commandline and modify our .getmailrc
like this:

Code:

...(settings for acc1)
#postmaster = ~/.muttmail/box1/            # Default delivery to this Maildir
postmaster = "|/usr/bin/procmail -m DEFAULT=/full/path/to/box1/ ~/.procmailrc"
...

...(settings for acc2)
#postmaster = ~/.muttmail/box2/            # Default delivery to this Maildir
postmaster = "|/usr/bin/procmail -m DEFAULT=/full/path/to/box2/ ~/.procmailrc"


Configuring procmail goes beyond this little help, but it's easy
enough to make it on your own.

One last point about procmail: if you execute
Code:

procmail -v


you'll see "Your system mailbox: /some/path/". For some reason this
shows me ~/.maildir/ all the time, regardless what's standing in
procmailrc. Never mind. Just ignore it. MAILDIR will be used as
defined in the rc-file.

Now go on, grep your spamfilter, add it to procmail, and ... and ...
and ... , but that's an other documentation :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Appendix B:

Here are some additional settings for your muttrc you might want
to have a look at:

---- Managing your mailboxes ----

Code:
# you can run shellprograms
mailboxes `echo ~/.muttmail/*`
# or set something by hand
# using shortcuts may help:
# = refers to your $folder directory
# ~ refers to home directory
# see manual for further shprtcuts, at this point you won't need more of them
#mailboxes =havens
#mailboxes =gmx

# Save copies of outgoing e-mail this has to be a maildir, where
# you have a look at by simply pressing "c". it will show up as
# one of your ordinary mail-dirs
set record="=sent-mail"


--- Using folderhook to set some options ----

Code:
# ~~~~~~~~~~~~
# folderhooks
# ~~~~~~~~~~~~

# with folder-hook you have to be carefull. it the pattern somehow matches
# any folder-definition, it matches: eg
# folder=home/name1/.mail/
# box1=name1isp1
# box2=name2isp2
# the folderhook mit pattern name1 will therefore match folder box2 and(!)
# for $folder
# so try to prevent names that appear more than once in a path

# i want to see, which account i'm viewing at the moment, so i add the name at
# the beginning of the status_format. additionaly i want to prereset my header.
# later i define a keybinding to set sendmail-command for my different isp.
# (ok, i now it because of the folder name, but it's more an example for using options
# with linebreaking)

# as mentioned by iob, i set also Reply-To, cause some
# freemailers wont relay without proper address


folder-hook . \
 'unmy_hdr *; \
  set status_format="-%r-%v--[%?M?%M/?%m msgs%?n?, %n new?%?d?, %d del?%?F?, %F flag?%?t?, %t tag?%?p?, %p postp?%?b?, %b inc?%?l?, %l?]--(%f)--%s-%>-%P-"'

folder-hook box1 \
 'set status_format="isp1 -%r-%v--[%?M?%M/?%m msgs%?n?, %n new?%?d?, %d del?%?F?, %F flag?%?t?, %t tag?%?p?, %p postp?%?b?, %b inc?%?l?, %l?]--(%f)--%s-%>-%P-"; \
  my_hdr From: name1@isp1.net ; \
  my_hdr Reply-To: name1@isp1.net'

folder-hook box2 \
 'set status_format="isp2 -%r-%v--[%?M?%M/?%m msgs%?n?, %n new?%?d?, %d del?%?F?, %F flag?%?t?, %t tag?%?p?, %p postp?%?b?, %b inc?%?l?, %l?]--(%f)--%s-%>-%P-"; \
  my_hdr From: name2@isp2.net ; \
  my_hdr Reply-To: name2@isp2.net'


---- Misc options ----

Code:
# do not save attachments from outgoing emails
unset fcc_attach

# i'm using 2 (or more)  accounts, so let's tell mutt about it
alternates name1@isp1.net name2@isp2.net

# mailinglists
subscribe list1@someisp.net
subscribe list2@someisp.net


---- settings in other files to get everything a bit structured ----

Code:
# load keybindings
source ~/.mutt/keybind

# load colors
source ~/.mutt/color

# email-aliases
source ~/.mutt/aliases


all my keybindings are no located in ~/.mutt/keybind

i've a colortable and put it seperately in ~/.mutt/color
Code:
# color patterns for mutt
color normal     white          black # normal text
color indicator  yellow         default # actual message
color tree       brightmagenta  default # thread arrows
color status     yellow         default # status line
color error      brightred      default # errors
color message    magenta        default # info messages
color signature  magenta        default # signature
color attachment brightyellow   red     # MIME attachments
color search     brightyellow   red     # search matches
color tilde      brightmagenta  default # ~ at bottom of msg
color markers    red            default # + at beginning of wrapped lines
color hdrdefault cyan           default # default header lines
color bold       red            default # hiliting bold patterns in body
color underline  green          default # hiliting underlined patterns in body
color quoted     cyan           default # quoted text
color quoted1    magenta        default
color quoted2    red            default
color quoted3    green          default
color quoted4    magenta           default
color quoted5    cyan           default
color quoted6    magenta        default
color quoted7    red            default
color quoted8    green          default
color quoted9    cyan           default
color body   cyan  default  "((ftp|http|https)://|news:)[^ >)\"\t]+"
color body   cyan  default  "[-a-z_0-9.+]+@[-a-z_0-9.]+"
color body   red   default  "(^| )\\*[-a-z0-9*]+\\*[,.?]?[ \n]"
color body   green default  "(^| )_[-a-z0-9_]+_[,.?]?[\n]"
color body   red   default  "(^| )\\*[-a-z0-9*]+\\*[,.?]?[ \n]"
color body   green default  "(^| )_[-a-z0-9_]+_[,.?]?[ \n]"
color index  cyan  default  ~F         # Flagged
color index  red   default  ~N         # New
color index  magenta    default  ~T         # Tagged
color index  cyan       default  ~D         # Deleted


some email-adds i often write to, i've in this file ~/.mutt/aliases
it's of the form:
Code:
alias friend1 friend1semailadd@hisisp
alias friend2 friend2semailadd@hisisp

so when your editor asks you the email-add you want to write to, friend1 will automatically be replaced by his emailadd


Last edited by Qubax on Thu Jul 15, 2004 12:43 pm; edited 4 times in total
Back to top
View user's profile Send private message
iob
n00b
n00b


Joined: 03 Mar 2004
Posts: 17

PostPosted: Sat May 22, 2004 9:44 pm    Post subject: Reply with quote

your "compose message" macro s hould also alter the "reply to:" adress as most freemailers wont relay the msg without proper adress.
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Thu Jun 17, 2004 1:43 pm    Post subject: Reply with quote

thanks, this helped me a lot.
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Thu Jun 17, 2004 1:50 pm    Post subject: Reply with quote

one question:
with the above setup, how do you view sent mail in mutt?

thanks.
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Thu Jun 17, 2004 2:08 pm    Post subject: Reply with quote

here's one way.

add this to .muttrc:
set record="~/.muttmail-sent"

then invoke mutt with:
mutt -f .muttmail-sent/

it'd be nice to be able to see it without exiting mutt though. maybe a "mailboxes =" setting? although i think that was designed for incoming mail.
Back to top
View user's profile Send private message
Qubax
Guru
Guru


Joined: 19 Jul 2002
Posts: 451
Location: Tirol, Austria

PostPosted: Wed Jun 30, 2004 11:04 am    Post subject: Reply with quote

add this to your muttrc:
Code:
# Save copies of outgoing e-mail
set record="=sent-mail"
then you can switch to the send-dir like to any other mail-dir, eg by pressing c
Back to top
View user's profile Send private message
SerfurJ
l33t
l33t


Joined: 10 Apr 2004
Posts: 824
Location: Texas

PostPosted: Wed Jun 30, 2004 1:53 pm    Post subject: Reply with quote

my muttrc has:
Code:
set record="~/.muttmail-sent"

so that sent mail will be saved in that directory.

i tried adding this to/replacing with:
Code:
set record="=sent-mail"

the sent-mail option didn't show up when i pressed c.

is your sent-mail directory beneath your incoming mail maildir?
Back to top
View user's profile Send private message
Qubax
Guru
Guru


Joined: 19 Jul 2002
Posts: 451
Location: Tirol, Austria

PostPosted: Sat Jul 03, 2004 11:52 pm    Post subject: Reply with quote

you were right: i also use a mialboxes-command. i think i'm going to add an "appendix b" for further options

have a look a this, i think this might help you
Code:
# you can run shellprograms
mailboxes `echo ~/.muttmail/*`
# or set something by hand
# using shortcuts may help:
# = refers to your $folder directory
# ~ refers to home directory
# see manual for further shprtcuts, at this point you won't need more of them
#mailboxes =havens
#mailboxes =gmx
Back to top
View user's profile Send private message
opo
n00b
n00b


Joined: 28 Jun 2004
Posts: 32
Location: Rome, Italy

PostPosted: Sun Jul 11, 2004 11:25 pm    Post subject: Reply with quote

This post is still useful after more than 2 years!!!
Thank U Qubax, still there?
Back to top
View user's profile Send private message
psyqil
Advocate
Advocate


Joined: 26 May 2003
Posts: 2767

PostPosted: Wed Jul 14, 2004 2:48 pm    Post subject: Reply with quote

opo wrote:
This post is still useful after more than 2 years!!!
Thank U Qubax, still there?
8O :?:
Qubax wrote:
date: 11/05/04

Anyway, nice post :D , but instead of having to press C-a1 or so (which, btw, didn't work for me...), I defined folder-hooks, as my incoming mail get's filtered into respective maildirs:
Code:
folder-hook =isp1 my_hdr From: psyqil <psyqil@isp1.com>
folder-hook =isp1 set 'sendmail="/usr/bin/msmtp -d -a isp1"'
folder-hook =isp2 my_hdr From: psyqil <psyqil@isp2.com>
folder-hook =isp2 set 'sendmail="/usr/bin/msmtp -d -a isp2"'


Concerning sent mail, as for 'historical reasons' they are in ~/.maildir-sent, I symlinked that into .muttmail/sent.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum