# send mail config
1 2 3 4 5 6 7 8 9 10 11 12 |
# 1) If sendmail is not installed, do install it: $apt-get install sendmail # 2) Configure hosts file correctly: $nano /etc/hosts #And make sure the line looks like this: 127.0.0.1 localhost localhost.localdomain yourhostnamehere $/etc/init.d/networking stop $/etc/init.d/networking start $sendmailconfig |
1 |
$ echo "My test email being sent from sendmail" | /usr/sbin/sendmail me@kutayzorlu.com |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#!/bin/bash # kutayzorlu.com # some variables # refactoring the script such that all these values are # passed from the outside as arguments should be easy from="sender@kutayzorlu.com" to="recipient@kutayzorlu.org" subject="Some fancy title" boundary="ZZ_/afg6432dfgkl.94531q" body="This is the body of our email" declare -a attachments attachments=( "foo.pdf" "bar.jpg" "archive.zip" ) # Build headers { printf '%s\n' "From: $from To: $to Subject: $subject Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=\"$boundary\" --${boundary} Content-Type: text/plain; charset=\"US-ASCII\" Content-Transfer-Encoding: 7bit Content-Disposition: inline $body " # now loop over the attachments, guess the type # and produce the corresponding part, encoded base64 for file in "${attachments[@]}"; do [ ! -f "$file" ] && echo "Warning: attachment $file not found, skipping" >&2 && continue mimetype=$(get_mimetype "$file") printf '%s\n' "--${boundary} Content-Type: $mimetype Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=\"$file\" " base64 "$file" echo done # print last boundary with closing -- printf '%s\n' "--${boundary}--" } | sendmail -t -oi # one may also use -f here to set the envelope-from |