Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sendmail on command line problem

Status
Not open for further replies.

elpis13

IS-IT--Management
Dec 12, 2005
7
Hello,

i try to send an email with sendmail on command line, i don't know how to attach a file and how to i give a subjectline with it. Any ideas?


Thank you!
 
The following presumes that you have the mailx package installed:

1. Write your desired message body out to a file. In this case, we will call the file example.txt

2. Uuencode your attachment, and append this to example.txt

3. Execute the following command, where "recipient_list" is a comma delimited list of email addresses:
Code:
cat example.txt | mail -s "[b]subject[/b]" [b]recipient_list[/b]
 
I use the sendmail command. I describe the sender with -f option,the -s option does not go with sendmail, my instruction looks in such a way:

#sendmail -f user.test recipient_list
 
Insert whatever headers you require at the top of the message body. i.e. example.txt will look like:

Code:
Subject: Test message

This is my example message body

begin 660 attachment.zip
M4$L#!!0````(`)A;C3.7+V\;\*```!,0!@`0`!4`4D5/4T%,15,Q,S,X+E18
M5%54"0`#P/:>0[;VGD-5>`0`R0#(`,V]6Z\<.9(F^-Z_XF`#&,P`%=%.,U[G
etc
etc
etc

`
end

Now you send the message:

Code:
cat example.txt | sendmail -f sender@example.com recipient_list

This will result in a message sent to the recipient list from sender@example.com with a subject "Test Message" a body of "This is my example message body" and an attachment "attachment.zip"

You can add additional header information as wanted/needed (i.e. add "X-Extra-Header-Info: Test" beneath the subject header above, and you will find that in the headers section of the message.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top