Monday, January 5, 2015

email - How to set up mutt so that it saves the sent messages to specific remote IMAP folder via bash scripts?


I've installed Zimbra Collaboration Suite on CentOS 7. I need to use mutt to send an email every hour.


The problem is whenever my script executes mutt, it does not save the message into specific (remote IMAP) folder in the .muttrc.


Meanwhile, when I execute the command directly, it does save the message into the folder.


This is my .muttrc configuration, resides in the current user home who executes the script:


set from="IP Address Information "
set folder="imaps://username:password@localhost"
set mask="!^\\.[^.]"
set record="+IPInfo"
set postponed="+Drafts"
set spoolfile="+INBOX"
set edit_headers=yes
set ssl_starttls=yes
set ssl_force_tls=yes
set smtp_url = "smtp://username:password@localhost:587"

This is the mutt invocation, executed by cron every hour:


echo "Test" | mutt -s "IP Address Information" destination@email.address

If I were to invoke the command like this:


mutt -s "IP Address Information" destination@email.address

and follow the process (mutt opens vi and let me type the body), it does saves the message to the folder. But then I cannot put this command to the script as it was meant to be automatic.


This is the destination folder I mentioned:


[screenshot of zimbra](http://imgur.com/U8EnQ6M)


Answer



Recently I've split the location of mutt and Zimbra, and found out there was a certificate problem during email delivery.


mutt is awaiting confirmation to accept or reject a certificate, and if it runs without interactivity, it automatically rejects the certificate. [this is my assumption of the behavior]


Here is an updated .muttrc:


set from="IP Address Information "
set folder="imaps://username:password@zimbra_or_postfix_server"
set mask="!^\\.[^.]"
set record="+IPInfo"
set postponed="+Drafts"
set spoolfile="+INBOX"
set edit_headers=yes
set certificate_file=.mutt-certs
set ssl_starttls=yes
set ssl_force_tls=yes
set smtp_url = "smtp://username:password@zimbra_or_postfix_server:587"

I was looking for the solution to this problem, and found the answer here: http://www.seas.upenn.edu/cets/answers/mutt-certificates.html which explained that I have to add set certificate_file directive to a file.


After letting mutt save the self-signed certificate, the script can once more deliver email to the MTA. But when I check to the mailbox of the account in use for the delivery, there is a folder named 'IPInfo' that follows the set record directive. And therefore I assume that the solution to my original problem is to let mutt save the self-signed certificate.


I hope this helps anyone who is looking for the similar answer.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...