How can I send an HTML email using a shell script?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First you need to compose the message. The bare minimum is composed of these two headers:
… and the appropriate message body:
Once you have it, you can pass the appropriate information to the mail command:
This is an oversimplified example, since you also need to take care of charsets, encodings, maximum line length… But this is basically the idea.
Alternatively, you can write your script in Perl or PHP rather than plain shell.
Update
A shell script is basically a text file with Unix line endings that starts with a line called shebang that tells the shell what interpreter it must pass the file to, follow some commands in the language the interpreter understands and has execution permission (in Unix that’s a file attribute). E.g., let’s say you save the following as
hello-world:Then you assign execution permission:
And you can finally run it:
Whatever, this is kind of unrelated to the original question. You should get familiar with basic shell scripting before doing advanced tasks with it. Here you are a couple of links about bash, a popular shell:
http://www.gnu.org/software/bash/manual/html_node/index.html
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html