Skip to main content

Send Email(with subject,body,attachment) using SSMTP through Terminal in linux?




1.Install ssmtp as

           $ sudo apt-get update && sudo apt-get install ssmtp

2.Configure smtp file by editing the following file as,

$ sudo gedit /etc/ssmtp/ssmtp.conf
Update file with the following:
AuthUser=Sendermail@gmail.com
AuthPass=SenderPasswordforGMAIL
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

Now ssmtp.conf file should look like as the following one,

AuthUser=Sendermail@gmail.com
AuthPass=SenderPasswordforGMAIL
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
# Where will the mail seem to come from?
#rewriteDomain=
# The full hostname
hostname=tele-desktop118
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
UseSTARTTLS=YES



3.Send a sample mail to test whether ssmtp is configured properly or not?
 Replace recipient email address with the proper email to test ssmtp


Now after pressing ENTER key,copy and paste following

To: recipient_email@example.com
From: sender_email@gmail.com
Subject: test email

hello world!

Replace From,To addresses with proper email addresses and Note the blank like after the subject, everything after this line is the body of the email. When you’re finished,

press Ctrl-D. sSMTP may take a few seconds to send the message before closing.

(or) using following simple way as

echo "Testing...1...2...3" | ssmtp receiver@gmail.com


4.To send an attachment using ssmtp we need to install mpack using following command

$  sudo apt-get install mpack

$ mpack -s “Subject_heading”  /path/to/file recipient_email@example.com

To attach body,we need to store text of the body to any variable as

$ echo "This mail is sent with an attachment using ssmtp on 19/03/2018 @ 12.00PM " > BODY


Now we can send subject,body,attachment to the recipient as

$ mpack -s "Subject_heading" -d BODY  /path/to/file recipient_email@example.com


Comments

  1. Nice post it is very useful for all. We provide all type of services like Bulk SMS, bulk email marketing, bulk sms reseller, smpp etc.

    ReplyDelete

Post a Comment

Popular posts from this blog

Backup (or) Download MYSQL Database as a zip file Using PHP

NOTE:Please change below credentials  with respect to your Database and Run the file. <?php define ( "DB_USER" ,  'DatabaseUSERNAME' ); define ( "DB_PASSWORD" ,  'DatabasePASSWORD' ); define ( "DB_NAME" ,  'DatabaseNAME' ); define ( "DB_HOST" ,  'localhost' ); define ( "BACKUP_DIR" ,  'myphp-backup-files' );  // Comment this line to use same script's directory ('.') define ( "TABLES" ,  '*' );  // Full backup //define("TABLES", 'table1, table2, table3'); // Partial backup of required tables define ( "CHARSET" ,  'utf8' ); define ( "GZIP_BACKUP_FILE" ,  true );   // Set to false if you want plain SQL backup files (not gzipped) class  Backup_Database {     var  $host ;     var  $username ;   ...

What is CronTab? What does it do?

What if you want to execute a file daily at particular time ? Running it manually daily is  absolutely not a good idea ..!   Then What do you do ? For this kind of manual works , To Automate it , there is a daemon in linux called "CRONTAB" . Crontab : Crontab called as CRON TABle Where  cron is a daemon to run periodically on a given time and Table consists of scheduled tasks , jobs  i . e , Crons . Crontab Options:    crontab - l : lists all the crontabs scheduled . crontab - e : Edits existing cron or else create new cron. crontab - r : Removes scheduled cron jobs . crontab - i - r : Prompts before deleting user 's crontab i.e,asks your permission.  crontab -u username -l : lists all the crons of a particular user.    Setting up a cron: Press Ctrl+Alt+t to open the terminal ...