LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   mail (https://www.linuxquestions.org/questions/linux-newbie-8/mail-343175/)

boopadedoo 07-14-2005 12:51 PM

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

How can I change the return address using mail or sendmail in Linux in a script.

rose_bud4201 07-14-2005 01:24 PM

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
Code:

    # 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 = f.read()
    f.close()

    #Let myself know the updated URL
    message = message + "\nhttp://www.cybermenology.com/Comments/" + filename

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

    #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:
Code:

[laura@cybermenology.com]$ cat emailtext
To: my_email_address@yahoo.com
From: automated.process@cybermenology.com
Reply-to: laura@cybermenology.com
Subject: New comment

Email message ...words words words....shtufff...blah.

And that's all there is to it.


All times are GMT -5. The time now is 04:34 PM.