bobdeath has asked for the wisdom of the Perl Monks concerning the following question:

Ok, I am needing to email from a current application I am working on. I am using Mail::Sendmail to accomplish this. The problem that I am having is determining where the mail is from. In the API to the module, I have to pass in the address the email is sent from. I want to somehow detect which address sent the email. Anyone have any ideas?

Replies are listed 'Best First'.
Re: Where is the Email coming from?
by CountZero (Bishop) on Jun 05, 2003 at 21:39 UTC

    If you are on a network, don't the users have to log-in somehow and is this login-ID not available, perhaps as some form of environment-variable?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Where is the Email coming from?
by teabag (Pilgrim) on Jun 06, 2003 at 10:49 UTC
    Hmm, it seems a little tricky and possibly not waterproof but ok,

    If your server is also the mailserver, and if the login/usernames are like user@myserver.com, try the method that the great Dave Roth uses to retrieve user info, find out the user, and just concat the user/loginname @myserver.com.

    The NetUser.pl Script should help you with how to do this.
    And you find that one here: http://www.roth.net/perl/scripts/scripts.asp?NetUser.pl

    Good luck,
    Teabag
    Sure there's more than one way, but one just needs one anyway - Teabag

Re: Where is the Email coming from?
by perrin (Chancellor) on Jun 05, 2003 at 20:31 UTC
    I'm not following. You want to detect where the mail is coming from? Isn't it coming from you? Or are you reading it in from some mail server?
Re: Where is the Email coming from?
by bm (Hermit) on Jun 06, 2003 at 10:03 UTC
    If I am understanding you correctly, you are asking how to come up with a correct value, 'me@here.com' for the From argument below:
    %mail = ( To => 'you@there.com', From => 'me@here.com', Message => "This is a very short message" ); sendmail(%mail) or die $Mail::Sendmail::error;

    I do not think it is possible to do this reliably every time - although another monk may well correct me on that. How to get that email address will differ from environment to environment.

    I am lucky, since in my environment users' email addresses take the form firstname.lastname@domain.com, so I can use the Unix `ypcat passwd` to find their full name, and construct their email address from that.

    If this is not possible, then perhaps a configuration file that maps userids to full email addresses is maybe the easiest (with all of its inherent maintenance headaches).

Re: Where is the Email coming from?
by bobdeath (Scribe) on Jun 05, 2003 at 20:36 UTC
    Sorry for any confusion, I am writing an application that will be used by many people on a network. When I use Mail::Sendmail to send an email, I have to tell it where the mail is coming from, in other words, the email address of the current user. I need some way to detect that.
      Don't know if this is an option, but if you use MIME::Lite and leave the From line blank it defaults to the userid on the server.