Ans: Here is the step by step process of sending email from linux:
To send emails from your Linux server, you need some basic tools:
-
A command-line email client (
s-nail
) -
An SMTP authentication library (
cyrus-sasl-plain
) -
And optionally,
postfix
(an MTA often required as a dependency for mail-related commands)
Next, you need to set up a configuration file that tells the mail
(or s-nail
) command how to send mail via Gmail. You’ll do this by editing a hidden config file in your home directory called .mailrc
.
Inside the file, you'll specify:
-
Gmail’s SMTP server and port
-
Authentication credentials
-
Security options (like STARTTLS)
-
Your "from" email address
Now that your config is ready, you can send an email using a single command. You provide:
-
The body text
-
The subject
-
The recipient email
Here is the detailed commands you can run to achieve above things:
-> sudo yum install postfix s-nail cyrus-sasl-plain
-> vi ~/.mailrc
-> vi ~/.mailrc
# Set MTA to use Gmail's SMTP server with STARTTLS
set mta=smtp://smtp.gmail.com:587
# Authentication settings
set smtp-auth=login
set smtp-auth-user=[email protected]
set smtp-auth-password=otvvzptnxcjrlvfn
# Email settings
set from="[email protected]"
# Enable TLS
set ssl-verify=ignore
set smtp-use-starttls
(Replace with your actual email and Gmail App Password)
-> :wq
-> echo "Leave message body, example: Need support on creating AWS account" | mail -s "subject of email" [email protected]
set mta=smtp://smtp.gmail.com:587
# Authentication settings
set smtp-auth=login
set smtp-auth-user=[email protected]
set smtp-auth-password=otvvzptnxcjrlvfn
# Email settings
set from="[email protected]"
# Enable TLS
set ssl-verify=ignore
set smtp-use-starttls
(Replace with your actual email and Gmail App Password)
-> :wq
-> echo "Leave message body, example: Need support on creating AWS account" | mail -s "subject of email" [email protected]
Here is the screenshot of the email:
No comments:
Post a Comment
If you have any doubt or question, you can post comment and I will check it.