Run sendmail on command line to determine if it is installed.
The line The program 'sendmail' can be found in the following packages:
implies it is not installed.
Run sudo apt install ssmtp to install sendmail.
Verify installation
Run echo "Subject: hello" | sendmail test@example.com
sendmail: Cannot open mail:25 is printed and it does not work. will be printed.
Mailhub settings need to be provided.
Configuring the SSMTP configuration file
View /etc/ssmtp/ssmtp.conf (need sudo privileges) to set up the
correct configuration properties.
Add the following lines and change the information between the each angle bracket as necessary
# Use TLS before starting negotiation.
UseSTARTTLS=YES
# The user that gets the emails.
root=<user@email.com>
# The mail server (where the mail is sent to), both port 465 or 587 should be
# acceptable. See also https://support.google.com/mail/answer/78799
mailhub=smtp.gmail.com:587
# The address where the mail appears to come from for user authentication.
rewriteDomain=gmail.com
# Username/App password for less secure apps.
AuthUser=<user@email.com>
AuthPass=lessSecureAppPassword
NOTE: This is using the gmail smtp server, which will need Google authentication to succeed.
From what I've tested, using the actual Google account password will not work, since this is
considered a "less secure app". 2FA will need to be turned on to enable a less secure app
password. Documentation can be found here.
NOTE 2: I could not find a way to use the built in Windows email so authentication isn't
needed. Steve had suggested using this way previously for the Sendmail command in
TSTool, but I'm not sure how that would work on the GCP VM.
Sending an email
Create a text file. As an example, mail.txt will be used.
Add in the following to the file, replacing the necessary information
in between each angle bracket <, >. Subject, CC and BCC are
not required.
To: <user@email.com>
Subject: <My Subject>
From: <user@email.com>
CC: <user@email.com>
BCC: <user@email.com>
This is the email body. You can write your message here, and all previously
added headers above will be cut out of the final message.
Thanks,
A friend.
Run the command
sendmail -t < mail.txt
The -t option will scan the email for headers, populate each one given,
and then remove it. Only the body text will be sent in the message.
Sending HTML in an email
Populating the contents of an email with HTML is an option as well by
adding Content-Type: text/html: charset="utf8" under the headers of the
email. Adding HTML in the message body can then be added and sent. For
example:
To: <user@email.com>
Subject: Test email
From: <user@email.com>
Content-Type: text/html; charset="utf8"
<html>
<body>
<div style="
background-color: #ff0000;
width: 300px;
display: inline-block;
height: 300px;">
</div>
You can add any valid email HTML here.
</body>
</html>
Sendmail Setup
Website used for reference and help:
https://blog.edmdesigner.com/send-email-from-linux-command-line/
Check if sendmail is installed
sendmail
on command line to determine if it is installed.The program 'sendmail' can be found in the following packages:
implies it is not installed.sudo apt install ssmtp
to install sendmail.Verify installation
echo "Subject: hello" | sendmail test@example.com
sendmail: Cannot open mail:25 is printed and it does not work.
will be printed.Configuring the SSMTP configuration file
/etc/ssmtp/ssmtp.conf
(need sudo privileges) to set up the correct configuration properties.NOTE: This is using the gmail smtp server, which will need Google authentication to succeed. From what I've tested, using the actual Google account password will not work, since this is considered a "less secure app". 2FA will need to be turned on to enable a less secure app password. Documentation can be found here.
NOTE 2: I could not find a way to use the built in Windows email so authentication isn't needed. Steve had suggested using this way previously for the Sendmail command in TSTool, but I'm not sure how that would work on the GCP VM.
Sending an email
Create a text file. As an example,
mail.txt
will be used.Add in the following to the file, replacing the necessary information in between each angle bracket
<
,>
.Subject
,CC
andBCC
are not required.-t
option will scan the email for headers, populate each one given, and then remove it. Only the body text will be sent in the message.Sending HTML in an email
Populating the contents of an email with HTML is an option as well by adding
Content-Type: text/html: charset="utf8"
under the headers of the email. Adding HTML in the message body can then be added and sent. For example: