I tried the below two commands.
From: mail_id
To: Recipient_mail_id
Hi, this is my message, and I'm sending it to you!
.
echo "My message" | sendmail -s subject Recipient_mail_id
But didn't get any mail to the recipient's mail address.
SMTP server is installed on another server and it is up and running. So can anyone help me out on how to send a test email through that SMTP server using sendmail or smtp commands?
sendmail
commandCreated a file with email content:
$ cat /tem/email.txt
Subject: Terminal Email Send
Email Content line 1
Email Content line 2
Now send email using the following command:
$ sendmail [email protected] < /tem/email.txt
mail
command$ mail -s "Test Subject" [email protected] < /dev/null
Also, you can send an attachment with this command. Use -a
for mailx and -A
for mailutils.
$ mail -a /opt/file.sql -s "Backup File" [email protected] < /dev/null
Also, we can add comma separated emails to send the email to multiple recipients together.
$ mail -s "Test Email" [email protected],[email protected] < /dev/null
mutt
command$ mutt -s "Test Email" [email protected] < /dev/null
Send an email including an attachment:
$ mutt -s "Test Email" -a /opt/backup.sql -- [email protected] < /dev/null
MTAs (Message Transfer Agents) like sendmail
expect email messages in Internet Message Format. Usually it is better to use a MUA (Message User Agent) (e.g. mail
), unless the message is trivially simple.
A "sendmail look alike" command is provided also by MTA/SMTP servers (postfix/exim/…) and programs like msmtp. Basic sendmail command line options are the facto standard so it may be a good choice for sending simple emails.
You may try the following shell script
#!/bin/sh
# sendmail command line optons:
# -i - do not treat lines starting with dot specially
# -t - read recipients lists from message headers: TO,CC,BCC
# -v - use verbose mode (describe what is happening)
#
# The empty line separates mail headers from mail body.
# Without -t recipients should be listed after command line options.
FROM='[email protected]'
TO='[email protected]'
/usr/sbin/sendmail -i -t << MESSAGE_END
To: ${TO}
From: ${FROM}
Subject: Example Subject
Hi, this is my message,
and I'm sending it to you!
MESSAGE_END
WARNING:
Sending text emails with non US-ASCII characters in email body requires extra headers (MIME). Another special encoding is required for non US-ASCII characters in email headers.
See RFC 2045 and related for further details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With