Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-14-2005, 12:51 PM   #1
LQ Newbie
Registered: Jul 2005
Location: California, USA
Posts: 1

Rep: Reputation: 0

In Unix I can use mailx to change the return address with the -r option, ie.
mailx -s "test" -r nobody < /tmp/foo

How can I change the return address using mail or sendmail in Linux in a script.
Old 07-14-2005, 01:24 PM   #2
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
Fairly simple - for example:
I've a script that runs on my website and lets me know when someone leaves me a comment. So, in my AddComment script, there's
    # Hijack the server's sendmail to send an email 
    MAIL = "/usr/sbin/sendmail"

    # get the email message from a file
    f = open('emailtext', 'r')
    message =

    #Let myself know the updated URL
    message = message + "\n" + filename

    # open a pipe to the mail program and
    # write the data to the pipe
    p = os.popen("%s -t" % MAIL, 'w')

    #Surprisingly enough, I don't really care what the exit code of the write() is.
    #if exitcode:
    #    print "Exit code: %s" % exitcode
The syntax for opening a system pipe may differ slightly depending on what language you're using. The above is python.

The actual text file containing the mail headers and the basic message is:
[]$ cat emailtext
Subject: New comment

Email message ...words words words....shtufff...blah.
And that's all there is to it.

Last edited by rose_bud4201; 07-14-2005 at 01:25 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to make Sendmail forward all incoming mail to localhost port 26 (Domino mail) speedgelb Linux - Software 3 09-27-2013 10:18 AM
Configure & Connect a Linux mail server from a windows mail clients digihall7 Linux - Networking 4 10-23-2006 12:21 PM
sendmail error Fetching mail could not lock /var/spool/mail/username sukhdev50 Linux - Networking 0 05-04-2005 03:41 AM
Exists a mail-client for Fedora, that can read local mail file without deleting? mxn Linux - Software 1 07-10-2004 12:53 PM
parsing mail.log with perl and calculate mail traffic on domain base markus1982 Programming 1 03-18-2003 06:22 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:44 AM.

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