How to send mail with body in linux
There are several ways to send an email with a body in Linux, depending on your specific needs and preferences. Here are a few options:
Option 1: Using the mail
command
You can use the mail
command to send an email with a body. Here's an example:
echo "Subject: My email" | mail -s "My email" [email protected]
This will send an email with the subject "My email" and a body that is the output of the echo
command.
Option 2: Using the sendmail
command
You can use the sendmail
command to send an email with a body. Here's an example:
sendmail -v [email protected] << EOF
Subject: My email
This is the body of the email.
EOF
This will send an email with the subject "My email" and a body that is the text between the EOF
markers.
Option 3: Using a mail client like mutt
You can use a mail client like mutt
to compose and send an email with a body. Here's an example:
mutt -s "My email" [email protected] << EOF
This is the body of the email.
EOF
This will open a new email composition window with the subject "My email" and a body that is the text between the EOF
markers.
Option 4: Using a scripting language like Python
You can use a scripting language like Python to send an email with a body. Here's an example using the smtplib
library:
import smtplib
from email.mime.text import MIMEText
msg = MIMEText("This is the body of the email.")
msg['Subject'] = "My email"
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"
server = smtplib.SMTP('your_smtp_server')
server.sendmail("[email protected]", "[email protected]", msg.as_string())
server.quit()
This will send an email with the subject "My email" and a body that is the text "This is the body of the email.".
These are just a few examples of how you can send an email with a body in Linux. The specific method you choose will depend on your specific needs and preferences.