• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

change sender email address

hi experts,

how can i change the from address of my emails sent through sendmail? Currently the emails are coming in this format: user@servername.domain.com. I'd like the emails to come in the following format: servername@domain.com.

seems like something simple but apparently not.

thanks in advanve for the help
0
telliot79
Asked:
telliot79
  • 8
  • 7
  • 3
1 Solution
 
xtermCommented:
Are these mails being sent via a webserver such as apache?  Or scripts/cronjobs?
0
 
telliot79Author Commented:
scripts.

i'm not entirely sure sendmail is the best tool for the job, feel free to suggest if it's not.
0
 
xtermCommented:
Here's how you'd do it with PHP:

mail("$to","$subject", $body, "From: $from","-f$from");

The -f part sets the return-path header to be customized so you don't see stuff like "root@host.domain.com" in there.

That is the easiest way.  If you HAVE to do it with a bash script, you can do something like this:

echo "HELO mydomain.com"; echo "MAIL FROM: me@mydomain.com"; echo "RCPT TO: recipient@otherdomain.com"; echo "DATA"; echo "To: <recipient@otherdomain.com>"; echo "Subject: My Subject"; echo "Body goes here"; echo "."; echo "QUIT") | telnet my.mailserver.com 25

You can put "sleep 1;" in between the commands if your mail server for some reason can't keep up with the speed of the script.


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
telliot79Author Commented:
almost there, the period for some reason, i keep getting stuck at "354 Start mail input; end with <CRLF>.<CRLF>"

i've tried modifying the script to echo " "; echo "."; echo " "; but that's not working either. any ideas?
0
 
xtermCommented:
Try put an echo "" right before the "Body goes here" echo - I think it needs a blank line after the headers.
0
 
telliot79Author Commented:
nope. i'll keep testing but am running out of ideas here
0
 
xtermCommented:
I'll play with it.  Don''t worry, we'll get it working.
0
 
telliot79Author Commented:
okay, plastered sleep 1 in between each command and have got it working (should have read your first msg a little more thorough.) only problem now is the message body has the subject in it, and not on the subject line. my script looks like this right now:

(echo "HELO <myemailserver>"; echo "MAIL FROM: <myfromaddress>"; echo "RCPT TO: <me>"; sleep 1; echo "DATA"; sleep 1; echo ""; sleep 1; echo "To: <me>"; sleep 1; echo ""; sleep 1; echo "Subject: My Subject"; sleep 1; echo ""; sleep 1; echo "Body goes here"; sleep 1; echo ""; sleep 1; echo "."; sleep 1; echo ""; echo "QUIT") | telnet <myemailserver> 25

almost there.
0
 
PapertripCommented:
Is there a specific reason you are trying to send a message through telnet instead of an MTA?
0
 
xtermCommented:
It's because you put echo "" between the To and the Subject header, which in essence tells the server, that everything after the empty line is part of the body.  Take out that echo and it will work nicely.

0
 
telliot79Author Commented:
thanks xterm, got it working.

papertrip - i'm just trying to have an email sent out after a crontab job has run, as you can see by this post and a few others from me in the last few days, I'm no UNIX guru. I have telnet working, and am happy with this, but would preferably like to use the recommended solution.
0
 
xtermCommented:
Papertrip:  He's using telnet to connect to and use a remote MTA, rather than using the local MTA because I suggested that to address his problem of not being able to do custom headers easily with the system /bin/mail command.
0
 
PapertripCommented:
If you are using sendmail, you can use masquerading to change all mails from servername.domain.com to domain.com.

Add this to your /etc/mail/sendmail.mc

MASQUERADE_AS(domain.com)dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_DOMAIN(servername.domain.com)dnl

Open in new window


then rebuild sendmail.cf & restart:

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
/etc/init.d/sendmail restart

Open in new window

0
 
xtermCommented:
telliot79:  I have been a Unix administrator since 1996, and I use that exact method of mailing on several of my servers.  You can solve the problem in multiple ways (I gave you a PHP example for instance) but none is necessarily "recommended" (certainly some are NOT recommended, but this is not one of them.)

At any rate, glad I could help you to get it working.  Take care.
0
 
PapertripCommented:
Personally I would use xterm's php mail() suggestion.
0
 
xtermCommented:
Papertrip:  Your solution will change the domain name, but the scripted cron emails are still going to come from root@domain.com, rather than the author's actual email address unless he adds a user to match that, and runs the cron as that user.  My solution is a lot simpler, and doesn't require changing the server's sendmail configs.
0
 
telliot79Author Commented:
thanks fella's for the insight. i clearly need to do a little more research on the options available, but for now, Telnet was the easiest solutoin for me given that I've used this before from a windows environment. I appreciate the help and hope I can repay the favour some day.
0
 
telliot79Author Commented:
first class help as always
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 8
  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now