Forum Discussion

David_G__33241's avatar
David_G__33241
Icon for Nimbostratus rankNimbostratus
Nov 06, 2015

How to modify SMTP from-address?

I have the following SMTP Configuration:

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 ""
echo ""
echo "Your password is: 12345"
echo "
") | 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.

Thanks,

David

APM 11.5.3

8 Replies

  • Lucas_Thompson_'s avatar
    Lucas_Thompson_
    Historic F5 Account

    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.

     

    • David_Gill's avatar
      David_Gill
      Icon for Cirrus rankCirrus
      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?
    • David_Gill's avatar
      David_Gill
      Icon for Cirrus rankCirrus
      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.
    • David_Gill's avatar
      David_Gill
      Icon for Cirrus rankCirrus
      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.