Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters

How to modify SMTP from-address?

I have the following SMTP Configuration:

Image Text

Regardless of what I have above, when I use the Email Agent in the VPE I can type anything I want in the From field and that is what will show when the recipient gets the email. If can be a full email address like name@company.com or something simple such as David – both work.

When I use sendmail from a script, the email always shows as coming from root [root@hostname.company.com] (display name is root, email address is root@hostname.company.com). This happens whether I log in as David or Admin.

My basic script works like this:

(echo "Subject: Your Password"
echo "To: recipient@company.com"
echo "Content-Type: TEXT/HTML; charset=US-ASCII"
echo ""
echo "<style> .blue { color: blue;} </style>"
echo "<body style=\"font-family:arial;font-size:13px\">"
echo "Your password is: <span class=\"blue\">12345</span>"
echo "<br><br></body>") | sendmail recipient@company.com

I have tried adding “From: sender@company.com” and –fsender@company.com but it always comes out as root [root@hostname.company.com]. Not sure if it makes a different but 100% of the mail is staying internal which is why I want to change the name of the Sender to something like vpn@company.com.


APM 11.5.3

Rate this Question

Answers to this Question


SMTP has two Froms, one is in the SMTP commands (FROM xxx) and the other is in the message headers (From: xxx). I think there is some way to get sendmail to read the headers to infer the "FROM" it should use, but you can just use the -f switch to set it when you call it from a script. This is more of a unix question rather than APM: The delivery agent used by APM is completely separate from sendmail.

Your command would then look like:

echo "message data here" | sendmail -f 'ops-noreply@company.com' 'recipient@company.com

Google "sendmail from address" for more in depth discussion on this topic and information about how different user agents need this to be formatted to display a "friendly name" part of the address. Also be sure to sanitize username input if it's from an external source, especially those usernames with apostrophes, parens, or shell script injection attacks.

Comments on this Answer
Comment made 06-Nov-2015 by David G. 369
It does not work for me. Even using the simplest format as you have shown above still comes out as root [root@hostname.company.com]. I tried with single quotes, double quotes, no quotes, space after the -f, no space after the -f. Does that one line sendmail command work for you?

These are two different functionalities. In order to have you sendmail command use a different from address you will have to edit the FromLineOverride=YES field in /etc/ssmtp/ssmtp.conf. This is SOL isn't exactly what you are doing, but it is leveraging the same functionality and explains how to edit the conf file.


Comments on this Answer
Comment made 08-Nov-2015 by David G. 369
The FromLineOverride=YES entry does work however it does not survive a reboot. Another user posted a very similar question and reference was made to https://support.f5.com/kb/en-us/solutions/public/11000/900/sol11948.html which talks about modifying /config/startup. Would this be the way to go and if so would I call a script just to replace /etc/ssmtp/ssmtp.conf with an updated version? It seems odd that if we are supposed to use tmsh modify /sys outbound-smtp to set the mailhub that it would not work for other parameters in the file.
Comment made 03-May-2018 by Jason Adams

FYI: This option can now persist reboots thanks to a new tmsh option:

K27540405: The tmsh command now supports the RewriteDomain and FromLineOverride SSMTP configuration