2

Can mutt send mail from command line without command line parameters, with subject, cc, bcc, reply-to, in-reply-to all defined inside mail.txt file with body of the message too (the same file format like mutt opens to me when i press m-send mail, or r-reply to mail).

... So that I can:

  • press 'r' on received mail, prepare my reply message, save it with ':w ~/preparedmail.txt' in vim ... cancel sending
  • and than run $ at 8:00 <<< "mutt < ~/preparedmail.txt"

... or is there other tool that will accept this file format. Or other way to achieve this.

  • 1
    if you can run at 8:00 am <<< mutt , what's the problem with using command-line options, e.g. running at 8:00 am <<< cat ~/preparedmail.txt | mail -s subject recipient@example.com ? – cas Nov 6 '15 at 6:45
  • @cas it is grate when i want to send new message. But when i want to REPLY there are special headers that i want to invoke, like in-reply-to: hexNumbersLine ...and mutt itself prepare all that well in interactive use with 'r' shortcut, it also prepares 'include original message' and stuff. – MetNP Nov 6 '15 at 18:36
  • yes. you can write the msg in mutt, and save it to a file. you can use any mail program (mail, sendmail, a perl script, etc) to send it. – cas Nov 6 '15 at 21:50
  • @cas hm, sorry, so you actually meant 'mail' not 'mutt' inside your first comment. ok i will just find out what is most easy to configure for imap. – MetNP Nov 7 '15 at 1:04
  • what's imap got to do with it? you're saving your edited msg to ~/preparedmail.txt – cas Nov 7 '15 at 1:10
1

If you are using sendmail or postfix to deliver the mail, you can use

sendmail -t <~/preparedmail.tx

and it will extract the destination recipient(s) from any To: Cc: or Bcc: header lines in the file (upto the first blank line) and send the file as mail.


For people having configured a tool like mutt to send mail directly, an easy solution is to use msmtp, a program to send a prebuilt mail which also takes -t like sendmail to get the recipients, and is much easier to configure for smtp with credentials than postfix or sendmail. Here is an example ~/.msmtprc to send mail to gmail:

account gmail
 host smtp.gmail.com
 port 587
 tls on
 # from myname@gmail.com
 auto_from on
 auth on
 user myname@gmail.com
 # password mypassword
 passwordeval gpg -d ~/.msmtp.password.gpg

account default : gmail

Don't forget to chmod og= ~/.msmtprc.

  • nice, but configuring sendmail (which is also mail-server as i understand) for imap, than credentials... seems little complicated – MetNP Nov 6 '15 at 18:32
  • I agree. you could also look at msmtp, a program to send a prebuilt mail which takes -t like sendmail, and is much easier to configure for smtp with credentials than postfix or sendmail. – meuh Nov 7 '15 at 13:53
  • i am marking your answer as correct, because of now mentioning MSMTP too. For my situation (using external smtps's not own mail-server), msmtp is the BEST tool... maybe you should add that info inside 'for us without sendmail/postfix/exim ambitions', for external smtps like mutt+gmail users. – MetNP Nov 8 '15 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.