Skip to content

Instantly share code, notes, and snippets.

@goddoe
Last active June 27, 2018 05:38
Show Gist options
  • Select an option

  • Save goddoe/aa4fbd55011205785912128a211ee7ae to your computer and use it in GitHub Desktop.

Select an option

Save goddoe/aa4fbd55011205785912128a211ee7ae to your computer and use it in GitHub Desktop.
Methods of sending email from ubuntu

Methods of sending email from ubuntu

Method 1.

install

sudo apt-get install mailutils

usage

marco@dagobah:~$ mail -v marco.ceppi.use@gmail.com
Subject: Hello World!
This is an email to myself.

Hope all is well.
.
Cc: 

You terminate messages with a single . on line. That's when mail will prompt you for Cc: enter the information (or leave blank) and mail will then print out additional information on what it is attempting to do, as well as detailing the processing of connecting, transmitting, and receiving data from the mail server.

Method 2.

install

apt-get install libio-socket-ssl-perl libnet-ssleay-perl sendemail

usage

sendemail -f fromuser@gmail.com -t touser@domain.com -u subject -m "message" -s smtp.gmail.com:587 -o tls=yes -xu gmailaccount@gmail.com -xp gmailpassword 

Method 3.

install

sudo apt-get install ssmtp

change config

Edit the ssmtp config file:
gksu gedit /etc/ssmtp/ssmtp.conf
Append the following text:
root=username@gmail.com
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username
AuthPass=password
FromLineOverride=YES
UseTLS=YES

usage

Run ssmtp and provide the recipient email address:
ssmtp recepient_name@gmail.com
Provide the message details as follows:
To: recipient_name@gmail.com
From: username@gmail.com
Subject: Sent from a terminal!

Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing. (Notice the blank space between the subject and the body.) Press Ctrl + D to send.

You can also put the text in file and send it as follows:

ssmtp recipient_name@gmail.com < filename.txt

Method 4.

install

apt-get install mpack

usage

mpack -s "file you wanted" ./data.pdf loser@supergoober.cn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment