Mail

From Network Security Wiki
Revision as of 13:55, 2 August 2017 by Amanjosan2008 (talk | contribs) (Protected "Mail" ([Edit=Allow only logged in users] (indefinite) [Move=Allow only logged in users] (indefinite) [Delete=Allow only logged in users] (indefinite)))

Sendmail

Installation

sudo apt-get install sendmail

Configuration for using SMTP server

sudo nano /etc/mail/sendmail.mc

At the end, add below below 2 line between existing 1st & 4th Line:

MAILER(`local')dnl
MAILER_DEFINITIONS
define('SMART_HOST',`smtp.gmail.com')
MAILER(`smtp')dnl

Now reconfigure sendmail to use above config:

sudo bash -c 'cd /etc/mail/ && m4 sendmail.mc >sendmail.cf'
sudo service sendmail restart

Troubleshooting

If you are unable to send emails, check below log file:

sudo cat /var/log/mail.err

If you get this error:

My unqualified host name (test-ubuntu) unknown; sleeping for retrytest-ubuntu

Edit hosts file to add below entries

sudo nano /etc/hosts
127.0.0.1       localhost.localdomain test-ubuntu


Testing

Manual Testing using Telnet

Connect to the server

telnet 127.0.0.1 25

If you see similar to below lines, you are connected to the server:

220 test-ubuntu ESMTP Sendmail 8.15.2/8.15.2/Debian-3; Wed, 2 Aug 2017 13:45:29 +0530; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]

Issue below commands/Inputs one by one to send a test mail:

HELO server
MAIL from:amanjosan2008@gmail.com
RCPT to: amandeep.singh@citrix.com
DATA
Subject:Test mail
hello amandeep.singh@citrix.com from amanjosan2008@gmail.com
This is the body
.

If you see this output, your mail is queued to be send:

250 2.0.0 v7289CNJ007111 Message accepted for delivery

Exit the program:

quit
Testing using CLI

Create a sample body file

nano body.txt

Paste below text into it:

Subject: test mail to Some Address!
From: Me <fromaddress@somemail.com>
To: Vasya<toaddress@somemail.com>
first line of my message

Send email using below command:

/usr/sbin/sendmail -t -f myaddress@gmail.com -v -i < body.txt

PHP Mail

/etc/php5/apache2/php.ini:
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "/usr/sbin/sendmail -t -f myaddress@gmail.com -i"

sudo service apache2 restart
PHP Script to send mail
sudo nano /var/www/html/mail.php
<?php
$to = "amandeep.singh@test.com";
$subject = "Alert Mail";
$txt = "This is an Alert Mail";
$headers = "From: Alert@test.com" . "\r\n" .
"CC: testuser@test.com";

mail($to,$subject,$txt,$headers);
?>
http://10.107.88.68/mail.php

Mutt

https://www.linux.com/blog/setup-mutt-gmail-centos-and-ubuntu
http://nickdesaulniers.github.io/blog/2016/06/18/mutt-gmail-ubuntu/
        This section is under construction.

SSMTP

https://askubuntu.com/questions/12917/how-to-send-mail-from-the-command-line
        This section is under construction.