LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-09-2014, 10:12 AM   #1
mohitvad
Member
 
Registered: Feb 2010
Posts: 34

Rep: Reputation: 0
specifying from email address while sending email


Hi,

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.com abc@xyz.com

I also tried below way but it is not happening
http://www.cyberciti.biz/tips/howto-...l-address.html
 
Old 05-09-2014, 12:13 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.)

So for your test:
mail -s "testing mail from other id" abc@xyz.com -- -f abc@gmail.com

Last edited by MensaWater; 05-09-2014 at 12:22 PM.
 
Old 05-09-2014, 12:29 PM   #3
mohitvad
Member
 
Registered: Feb 2010
Posts: 34

Original Poster
Rep: Reputation: 0
It did not work.
 
Old 05-09-2014, 12:41 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
"not work" is hardly useful for diagnosing issues.

Did you get an error when you typed it?

Did you NOT get an error and simply not receive the email?

Did you receive the email but NOT get it as the from user you specified?

Did you examine the full headers of the email you received?

Did you review your /var/log/maillog to see what it did when you told it to send the mail?

Is sendmail running on your system?
 
Old 05-09-2014, 01:51 PM   #5
mohitvad
Member
 
Registered: Feb 2010
Posts: 34

Original Poster
Rep: Reputation: 0
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
 
Old 05-09-2014, 02:18 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.com abc@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.
 
Old 05-09-2014, 02:41 PM   #7
mohitvad
Member
 
Registered: Feb 2010
Posts: 34

Original Poster
Rep: Reputation: 0
I don't know why the the sender is not changing. I am using the relay server IP in my environment. I don't know what is the possibility now.
 
Old 05-09-2014, 02:52 PM   #8
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Can you paste the relevant entries from your /var/log/maillog?

Can you paste the FULL headers from the email you do receive?
 
Old 05-09-2014, 02:59 PM   #9
mohitvad
Member
 
Registered: Feb 2010
Posts: 34

Original Poster
Rep: Reputation: 0
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 ?
 
Old 05-09-2014, 03:02 PM   #10
mohitvad
Member
 
Registered: Feb 2010
Posts: 34

Original Poster
Rep: Reputation: 0
If i send mail using mail command it is using other MTA. I want to use Postfix as a MTA.
 
Old 05-09-2014, 03:38 PM   #11
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
There should be a /usr/sbin/sendmail.postfix command.

If so you can create a file with the details you - call it testmail for example:
Code:
To: abc@xyz.com
From: abc.gmail.com
Subject: Test with sendmail postfix
Test
.
Note: The dot on the last line above is important.

run the sendmail.postfix using testmail as input:

/usr/sbin/sendmail.postfix -t <testmail
 
Old 05-10-2014, 12:17 PM   #12
mohitvad
Member
 
Registered: Feb 2010
Posts: 34

Original Poster
Rep: Reputation: 0
After changing parameter in the default MTA configuration i am able to send an email with the command "

mail -s "testing mail from other id" -r abc@gmail.com abc@xyz.com


Thanks for answering. now i am going to close the thread.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SMTP random ip address in sending email conflicker Linux - Newbie 5 12-19-2012 01:17 PM
Sending a form to an email address problems! cucolin@ Programming 1 06-23-2004 05:21 AM
Sending Email to an SMTP address from sendmail guilmetrp Linux - Newbie 6 03-01-2004 08:51 PM
Sending email to a smtp address through sendmail guilmetrp Linux - General 0 02-27-2004 08:02 PM
sending an email to a email address after a perl operation meluser Programming 9 04-07-2003 01:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration