Jump to content

Sending emails via command line: Difference between revisions

Line 66: Line 66:
===Method 1===
===Method 1===
----
----
For this first example, lets send an email from the hypothetical address '''[email protected]''' to '''[email protected]''' using Gmail's SMTP settings:
For this first example, lets send an email containing the message "'''Hello, JustTesting'''", from the hypothetical address '''[email protected]''' to '''[email protected]''' using Gmail's SMTP settings:


  echo -e "subject:Test\nfrom:[email protected]\nTesting" | sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1 -starttls smtp" -au"[email protected]" -ap"senders.email.password" [email protected]
  echo -e "subject:Test\nfrom:[email protected]\nHello,\n\nJustTesting" | sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1 -starttls smtp" -au"[email protected]" -ap"senders.email.password" [email protected]


Let's examine this command in detail. First, the '''echo <span style=color:green>-e</span> "<span style=color:blue>subject:Test</span><span style=color:red>\n</span><span style=color:blue>from:[email protected]</span><span style=color:red>\n</span><span style=color:blue>Testing</span>"''' part:
Let's examine this command in detail. First, the '''echo <span style=color:green>-e</span> "<span style=color:blue>subject:Test</span><span style=color:red>\n</span><span style=color:blue>from:[email protected]</span><span style=color:red>\n</span><span style=color:blue>Hello,</span><span style=color:red>\n\n</span><span style=color:blue>JustTesting</span>"''' part:


'''echo''' - prints the specified arguments to stdout
'''echo''' - prints the specified arguments to stdout


'''<span style=color:green>-e</span>''' - makes the echo command interpret backslash escapes (</span><span style=color:red>\n</span> in this case)
<span style=color:green>'''-e'''</span> - makes the echo command interpret backslash escapes (</span><span style=color:red>\n</span> in this case)
 
<span style=color:red>\n</span> - the end line symbol, i.e., it indicates that the following text begins in another line. The </span><span style=color:red>\n</span> part itself is not interpreted as part of the text if '''<span style=color:green>-e</span>''' is specified.


<span style=color:red>'''\n'''</span> - the end line symbol, i.e., it indicates that the following text begins in another line. The </span><span style=color:red>\n</span> part itself is not interpreted as part of the text if '''<span style=color:green>-e</span>''' is specified.


The text highlighted in blue specifies the mail's header information (excluding the recipient's address) and body. In our case it represents this:


'''Subject''': <span style=color:blue>Test</span>
'''From''': <span style=color:blue>[email protected]</span>
'''Body of text''':
<span style=color:blue>Hello,
JustTesting</span>
sendmail -v -H "exec openssl s_client -quiet -connect smtp.gma
sendmail -v -H "exec openssl s_client -quiet -connect smtp.gma
il.com:587 -tls1 -starttls smtp" <mail.txt -f [email protected] -au"d
il.com:587 -tls1 -starttls smtp" <mail.txt -f [email protected] -au"d