23

I have to send a mail with an attachment from a shell script. I am trying to do it using mutt as shown here: How do I send a file as an email attachment using Linux command line?

Command: echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.com

Error:

Error sending message, child exited 127 (Exec error.).
Could not send the message.

Community
  • 1
  • 1
Aditya
  • 1,136
  • 2
  • 12
  • 19

5 Answers5

22

I was having the same issue on Ubuntu 18.04 and just like @jono, I only had installed mutt. Installing

sudo apt-get install sendmail

After that, sending mail with the test method or straight through the mutt CLI worked perfectly.

Valentin M
  • 269
  • 2
  • 4
4

I had this error and had to simply add below to my .muttrc. I'm using Gmail if that matters. This way I'm using someone elses server to send and don't have to install extra junk.

set smtp_pass="secrets" set smtp_url = "smtps://username@gmail.com@smtp.gmail.com:465/"

zack999
  • 111
  • 2
3

I have encountered this same error today. I found I only had mutt installed, but once I installed sendmail this error went away. However I then got blocked locally. So I uninstalled sendmail, and installed postfix this worked.. Now receiving email with attached pdf.

This was on RHEL 7.4 in an enterprise environment. Unsure if results will differ on other versions or environments.

jono
  • 31
  • 3
1

set the password generated from this link into this file:

    # file: ~/.muttrc
    set from="first_name.last_name@gmail.com"
    set realname="first_name last_name"
    set imap_user="first_name.last_name@gmail.com"
    #
    # v1.0.1
    # check the following google help page:
    # http://support.google.com/accounts/bin/answer.py?answer=185833
    # that is set here your google application password
    set imap_pass="SecretPass!"
    #nopeset imap_authenticators="gssapi"
    set imap_authenticators="gssapi:cram-md5:login"
    set certificate_file="~/.mutt/certificates"
    #
    # These two lines appear to be needed on some Linux distros, like Arch Linux
    #
    ##REMOTE GMAIL FOLDERS
    set folder="imaps://imap.gmail.com:993"
    set record="+[Gmail]/Sent Mail"
    set spoolfile="imaps://imap.gmail.com:993/INBOX"
    set postponed="+[Gmail]/Drafts"
    set trash="+[Google Mail]/Trash"
    #
    ###SMTP Settings to sent email
    set smtp_url="smtp://first_name.last_name@smtp.gmail.com:587"
    #
    # v1.0.1
    # check the following google help page:
    # http://support.google.com/accounts/bin/answer.py?answer=185833
    # that is set here your google application password
    set smtp_pass="SecretPass!"
    #
    ###LOCAL FOLDERS FOR CACHED HEADERS AND CERTIFICATES
    set header_cache="~/.mutt/cache/headers"
    set message_cachedir="~/.mutt/cache/bodies"
    set certificate_file =~/.mutt/certificates
    #
    ###SECURING
    set move=no  #Stop asking to "move read messages to mbox"!
    set imap_keepalive=900
    #
    ###Sort by newest conversation first.
    set sort=reverse-threads
    set sort_aux=last-date-received
    #
    ###Set editor to create new email
    set editor='vim'

    set ssl_starttls=yes
    set ssl_force_tls=yes
Yordan Georgiev
  • 5,114
  • 1
  • 56
  • 53
1

Fix for GMail Account Configuration

The following post worked for me: https://www.codyhiar.com/blog/getting-mutt-setup-with-gmail-using-2-factor-auth-on-ubuntu-14-04/

But it was not very clear. The contents of ~/.muttrc that worked for me are as follows (My account has 2-Step verification enabled and I had to generate app password as described in the post):

set imap_user = "<username>@gmail.com"
set imap_pass = "<16-character-app-password>"

set sendmail="/usr/sbin/ssmtp"

set folder="imaps://imap.gmail.com:993"
set spoolfile="imaps://imap.gmail.com/INBOX"
set record="imaps://imap.gmail.com/[Gmail]/Sent Mail"
set postponed="imaps://imap.gmail.com/[Gmail]/Drafts"

set header_cache = "~/.mutt/cache/headers"
set message_cachedir = "~/.mutt/cache/bodies"
set certificate_file = "~/.mutt/certificates"

set from = "<username>@gmail.com"
set realname = "<name-used-in-the-gmail-account>"

set smtp_url = "smtp://<username>@smtp.gmail.com:587/"
set smtp_pass="<16-character-app-password>"

set move = no
set imap_keepalive = 900

# Gmail-style keyboard shortcuts
macro index,pager ga "<change-folder>=[Gmail]/All<tab><enter>" "Go to all mail"
macro index,pager gi "<change-folder>=INBOX<enter>" "Go to inbox"
macro index,pager gs "<change-folder>=[Gmail]/Starred<enter>" "Go to starred messages"
macro index,pager gd "<change-folder>=[Gmail]/Drafts<enter>" "Go to drafts"
macro index,pager e "<enter-command>unset trash\n <delete-message>" "Gmail archive message" # different from Gmail, but wanted to keep "y" to show folders.

Replace the following:

  1. <username>: Your gmail username
  2. <16-character-app-password>: You have to generate this
  3. <name-used-in-the-gmail-account>: Your name as per gmail account

Note: Don't change <change-folder>

BR M
  • 101
  • 7