Linux mail from address
In Linux, the From
address in an email is typically set using the MAILFROM
environment variable or the From
header in the email message.
Here are a few ways to set the From
address in Linux:
-
Using the
MAILFROM
environment variable: You can set theMAILFROM
environment variable in your shell configuration file (e.g.,~/.bashrc
or~/.zshrc
) to specify the desiredFrom
address. For example:export MAILFROM="[email protected]"
-
Using the
sendmail
command: When sending an email using thesendmail
command, you can specify theFrom
address using the-f
option. For example:sendmail -f "[email protected]" [email protected]
-
Using the
mail
command: When sending an email using themail
command, you can specify theFrom
address using the-s
option. For example:mail -s "Subject" [email protected] -f "[email protected]"
-
Using a mail client: If you're using a mail client like Mutt, Alpine, or Thunderbird, you can set the
From
address in the client's configuration settings. -
Using a script: You can also set the
From
address using a script that sends the email. For example, using Python and thesmtplib
library:import smtplib from email.mime.text import MIMEText
msg = MIMEText("Hello, world!") msg['From'] = "[email protected]" msg['To'] = "[email protected]" msg['Subject'] = "Hello, world!"
server = smtplib.SMTP('smtp.example.com') server.sendmail("[email protected]", "[email protected]", msg.as_string()) server.quit()
Note that the `From` address should be a valid email address that is recognized by the email server.