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
Authentication
Make auth subdirectory in mail config directory:
cd /etc/mail mkdir auth chmod 700 auth
Create a file with your auth information to the smtp server
cd auth touch client-info
In the file, put the following, matching up to your smtp server:
AuthInfo:mail.domain.com "U:root" "I:username" "P:password"
Generate the Authentication database, make both files readable only by root
makemap hash client-info < client-info chmod 600 client-info cd ..
Add the following lines to sendmail.mc. Make sure you update your smtp server
MAILER_DEFINITIONS FEATURE(`authinfo',`hash /etc/mail/auth/client-info.db')dnl MAILER(`local')dnl MAILER_DEFINITIONS define(`SMART_HOST',`mail.domain.com')dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl MAILER(`smtp')dnl
Invoke creation sendmail.cf
sudo sendmailconfig
Test Mail:
sendmail -t myaddress@gmail.com -v -i < body.txt
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
COnfigure PH to use Sendmail:
/etc/php5/apache2/php.ini:
Add at the end of this file:
; 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"
Restart Apache server:
sudo service apache2 restart
- PHP Script to send mail
Create a PHP file in the root Directory:
sudo nano /var/www/html/mail.php
Paste and save the below contents in it:
<?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); ?>
Your mail should be sent after you open below link in browser:
http://10.107.88.68/mail.php
SendEmail
Source: caspian.dotconf.net
Installation using apt:
sudo apt-get install sendemail
Manual Installation:
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz tar -zxvf /tmp/sendEmail-v1.56.tar.gz cd sendEmail-v1.56/ sudo cp -a sendEmail /usr/local/bin/ chmod +x /usr/local/bin/sendEmail
Testing:
sendEmail
Sending Email with inline attachment:
nano body.txt
<html> <img src="logo.png" alt="logo" align="right" height="40" width="120"/> <p>Hi,</p> <p>This is a test Alert Mail.</p> <p>Please find below the details about this Alert:<br /><br /></p> <p>There are the details.</p> </html>
sendEmail -f codered@domain.com -t amandeep.singh@domain.com -s mail.domain.com -u "Codered Test Mail" -o message-file=/home/test/body.txt -o message-content-type=html -a ~/logo.png
Misc
Figure out SMTP address
- Windows:
Open CMD.exe and type below commands:
nslookup set type=MX domain.name
- Linux:
dig domain.name MX
- References
{{#widget:DISQUS
|id=networkm
|uniqid=Mail
|url=https://aman.awiki.org/wiki/Mail
}}