Email Outside

How to send email to other servers.

Activity 1: Gmail App Password

You can send email programmatically using a class Gmail account, get the “App Password” from your teacher.

# read in the password invisibly
read -s password

email=merit.apcs@gmail.com
to=<your_email_here>

Send the email using Gmail from the server.

swaks -4 --server smtp.gmail.com -tlsc \
    --tls-protocol TLSv1_2 \
    --from $email --to $to --auth LOGIN \
    --auth-user $email --auth-password $password \
    -apt --h-Subject 'Test email' --body 'Email system test.' \
    --helo localhost

Scroll through the output and notice a few things.

<~  334 Username:
 ~> merit.apcs@gmail.com                                       
<~  334 Password: 
 ~> ************         
<~  235 2.7.0 Accepted   

The app password is printed in plain text to stdout. You can suppress output with the -S option.

[dbuckley@localhost ~]$ swaks --help | grep silent
    -S, --silent [ 1 | 2 | 3 ]
        Cause Swaks to be silent. If no argument is given or if an argument
        print errors. If "3" is given, show no output ever. "--silent"
        Windows, use SWAKS_OPT_silent instead. (Arg-Optional)
        (see "--silent"), and inability to have a "set but empty" value in

Here’s another line of note.

<~  250 2.0.0 OK  1789747893 46e09a7af769-80e3fd45252sm1878612a34.0 - gsmtp

This a response from Google’s SMTP server that it worked. Try an email without the password and see what happens.

Activity 2: Sending to the Internet from the server itself.

For a comprehensive guide on setting up a mail server, see https://workaround.org.

In order to set up a mail server to send to the internet, we need to set up some DNS records. You can check if things are set up properly at mxtoolbox.com.

DNS

These are the two main essential records. An A record points to the server.

A       cyber       174.141.222.95
MX      cyber       cyber.meritprepacademy.app

The BIMI record is to ensure a brand image shows up for the sender. DMARC is a policy for reporting dropped emails.

TXT     default._bimi.cyber        v=BIMI1; l=https://static.wixstatic.com/media/e544f1_91a05c19742046338589a831e8802380~mv2.png/v1/fill/w_194,h_152,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/Merit%20Logo.png
TXT     _dmarc.cyber               v=DMARC1; p=quarantine; pct=100; rua=mailto:dbuckley@cyber.meritprepacademy.app;

Ports and Firewall

To be continued…