How can I send an email using the UNIX mailx command

How can I send an email through the UNIX mailx command

+69
unix email mailx
Feb 17 '10 at 16:38
source share
9 answers

example

$ echo "something" | mailx -s "subject" recipient@somewhere.com 

send attachment

 $ uuencode file file | mailx -s "subject" recipient@somewhere.com 

and send the attachment and write the body of the message

 $ (echo "something\n" ; uuencode file file) | mailx -s "subject" recipient@somewhere.com 
+82
Feb 17 '10 at 16:48
source share
— -

Here you are:

 echo "Body" | mailx -r "FROM_EMAIL" -s "SUBJECT" "To_EMAIL" 

PS. The body and subject must be stored in double quotation marks. Remove quotation marks from FROM_EMAIL and To_EMAIL when replacing email addresses.

+23
Dec 31 '13 at 5:48
source share

Faster with the MUTT Team

e-mail body echo | mutt -a "File_Attachment.csv" -s "Daily report for $ (date)" -c cc_mail@g.com to_mail@g.com -y

  • -c list cc cc cc list
  • -s
  • -y send mail
+4
Jan 08 '13 at 11:34 on
source share
 mailx -s "subjec_of_mail" abc@domail.com < file_name 

through the mailx utility we can send the file from unix to the mail server . here, in the above code, we can see the first parameter -s "subject of mail" second parameter mail ID , and the last parameter is the name of the file we want to add

+4
Jun 01 '16 at 10:56 on
source share

On the man page:

Sending mail

To send a message to one or more people, mailx can be called using the arguments, which are the names of the people to whom the message will be sent. Then the user must enter his message using "control-D" at the beginning of the line.

In other words, mailx reads the contents to be sent from standard input and can be redirected to normal. For example:.

 ls -l $HOME | mailx -s "The content of my home directory" someone@email.adr 
+3
Feb 17 2018-10-17
source share
 mail [-s subject] [-c ccaddress] [-b bccaddress] toaddress 

-c and -b are optional.

-s: specify a subject, if the object contains spaces, use quotation marks.

-c: Send copies of the copies to the user list, separated by commas.

-b: send blind copies of copies to a comma separated list of users.

Hope my answer clarifies your doubts.

+3
Jun 26 '13 at 7:11
source share
 echo "Sending emails ..." NOW=$(date +"%F %H:%M") echo $NOW " Running service" >> open_files.log header=`echo "Service Restarting: " $NOW` mail -s "$header" abc.xyz@google.com, \ cde.mno@yahoo.com, \ < open_files.log 
+3
Dec 05 '14 at 18:32
source share

FOR Sending attachments using mailx below

Use the new attachment switch (-a) in mailx to send attachments with mail. The -a options are easier to use with the uuencode command.

 # mailx -a file.txt -s "Subject" user@domain.com 

The above command will print a new blank line. Enter the message text and press [ctrl] + [d] to send. This will correctly attach the file to the outgoing message with the appropriate Content-Type headers and borders.

To make this more "scriptable", you can send a message without a body with the following:

 # mailx -a file.txt -s "Subject" user@domain.com < /dev/null 

To send mail with the message body, replace / dev / null in the above command with your message body file.

+2
Sep 26 '17 at 14:09 on
source share

Outgoing Address Setting

 MESSAGE="SOME MESSAGE" SUBJECT="SOME SUBJECT" TOADDR="u@u.com" FROM="DONOTREPLY" echo $MESSAGE | mail -s "$SUBJECT" $TOADDR -- -f $FROM 
0
Dec 15 '16 at 16:49
source share



All Articles