Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the subject line and add attachment while using sendmail utility on linux?

Tags:

linux

sendmail

I am using sendmail utility on CentOs to send mail. I am not able to set the subject-line and add attachment for the mails which are sent using this utility. Using option "-s" to set the subject line is not applicable for sendmail utility. Please tell what options to use with the sendmail for achieving thses objectives.

like image 939
Amit Avatar asked Jan 09 '23 19:01

Amit


1 Answers

sendmail is a low-level utility. You have to compose the extra message headers yourself.

That is, to add the subject line, before the body of the message you prepend:

Subject: <your-subject>

And a new line to separate the headers from the body.

Likewise, to add the attachment:

Subject: <your-subject>
Content-Type: multipart/mixed; boundary="-unique-str"

---unique-str
Content-Type: text/html
Content-Disposition: inline

<html-body here>
---unique-str
Content-Type: application; name=<attachment-mime>
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=<attachment-name>

<your base64-encoded attachment here>
---unique-str--

Or something like this (I didn't test it).

You can see how real messages are formatted by looking at the "show original" or "show source" options available in most e-mail clients. Those options will show you the raw-message and you just need to build something similar.

like image 73
rodrigo Avatar answered Jan 19 '23 06:01

rodrigo