tonieee's blog

Mutt imap/smtp woes solved

Posted on November 29th, 2014 by tonieee

I love mutt. It is a very flexible and powerful email client but it can be quite hard getting the initial setup right. When I switched it from using pop3 to imap/smtp I had a few problems getting it to work.

First I was getting the following error whenever I tried to send a message:

SMTP session failed: 550

I had my smtp_url in my muttrc set up as follows:

set smtp_url="smtps://"

It turns out I needed to add my email address (e.g. emailname@email.domain) before the server name:

set smtp_url="smtps://"

The next problem was after I left mutt for a while and came back to it I was getting the following error:

tls_socket_write (Error in the push function.)

This was caused by the connection to the server timing out. By default mutt polls the server once every 10 minutes. You can fix this by changing the timeout property in muttrc. I changed mine to 60 seconds and now all seems fine:

set timeout=60

Another problem is the password. Two passwords are required: imap_pass for retrieving the mails and smtp_pass to send a message. If you leave these blank then mutt will prompt you for them but this means you have to enter the password twice (once when you open mutt and again when you send your first message) and also any changes to your mailbox won’t be synced back to the server unless you’ve already sent a message.

I could store the passwords in the file but don’t like leaving then in plain text in a file on my hard drive. I could encrypt them (as described here but then I would need to type a passphrase in to decrypt the password which kind of defeats the object or I could encrypt them with a key with no passphrase but that is not really much more secure than storing in plain text (though I guess that’s what other mail clients must do).

What I did was write a command in the muttrc to read in the password at startup and store in a variable which is then used by both imap_pass and smtp_pass.

set my_pass=`stty -echo; read -p 'Password: ' tmppwd; echo $tmppwd; tmppwd=; stty echo`
set imap_pass=$my_pass
set smtp_pass=$my_pass

The variable is called “my_pass” because mutt requires user defined variables to be prefixed with “my_“. The “stty -echo” is to stop the user input being displayed while they type the password and “stty echo” is to turn it back on again.

Finally, I was used to using G to refresh the inbox. Though with it now refreshing every 60 seconds it is not really necessary, but I’m impatient and I’d still like to sometimes be able to check for new emails instantly instead of waiting for a whole minute for them to show. I did it by binding the imap-fetch-mail command to G in my muttrc as follows:

bind index G imap-fetch-mail

This entry was posted on Saturday, November 29th, 2014 at 3:54 pm and is filed under Computers. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.