[SOLVED] specifying from email address while sending email
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to send an email from other email address. By default if i send an email my username@hostname goes out. I want to send an email using email id. I have centos 6.5. I tried mail command with options. Below are the ommands. but it is not working. Can anybody help please
mail -s "testing mail from other id" -r "From: abc@gmail.com" abc@xyz.com
mail -s "testing mail from other id" -r "abc@gmail.com" abc@xyz.com
mail -s "testing mail from other id" -aFrom:"abc@gmail.com" abc@xyz.com
mail -s "testing mail from other id" -S From="abc@gmail.com" abc@xyz.com
mail -s "$(echo -e "This is the subject\nFrom: abc@gmail.com\nContent-Type: text/html\n")" abc@xyz.com
echo "email body" | mail -s "Subject here" -r abc@gmail.comabc@xyz.com
Funny - I was just doing some testing with smarttable and reminding myself how to do this.
You can specify "sendmail" options after standard "mail" options with the "-- <options>".
So to do what you want use the mail option "-s" for the subject but then use the "sendmail" option "-f" to specify the alternate sender:
Sytnax would be:
mail -s <subject> <recipient> -- -f <sender>
(Note the "--" is followed by space THEN the "-f" - it is the "--" that tells it to use the "sendmail" options.)
No i didn't get any error
I received the email
No i am still getting an email username@hostname format
yes I examined but not getting anything in headers
I checked /var/log/maillog
Its postfix sending email
OK it appears the "mail/mailx" command changed between RHEL/CentOS 5 and RHEL/CentOS 6. The latter doesn't have the "--" for sendmail options but DOES have the "-r" for specifying the "from" sender.
The last syntax you had above worked for me using that "-r" on a RHEL 6.5 box running Sendmail:
echo "email body" | mail -s "Subject here" -r abc@gmail.comabc@xyz.com
It also worked on another RHEL 6.5 running Postfix instead of Sendmail.
Since it works on RHEL 6.5 it should work on CentOS 6.5 because it was compiled from RHEL 6.5 sources.
Menas thanks for your help. I just came to know the cause. I am near. I just came to know that their are couple of MTA postfix and one other . By default it is using other . I want to use postfix . Is there any command that should use the Postfix configuration . I mean is there a postfix binary that i can use to send an email with from address ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.