Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Net::SMTP and resolving an alias

by mdamazon (Acolyte)
on Aug 04, 2016 at 15:14 UTC ( #1169126=perlquestion: print w/replies, xml ) Need Help??

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

I can send an email via Net::SMTP with no problem as long as I use the actual email addresses of those that I wish to send an email.

$smtp = Net::SMTP->new(servername); $smtp->mail($ENV{REMOTE_HOST}); $smtp->to($email_address); $smtp->data(); $smtp->datasend("To: " . $what_ever); $smtp->datasend("From: name\ \n"); $smtp->datasend("Subject: whatever"); $smtp->datasend("\n"); $smtp->datasend($email_msg); $smtp->dataend();
If I create an email using my MS-Outlook client, I can just type in the user's login names in the To: form, press Ctrl-K, and it somehow looks up those names, called 'Alias', and converts them to real email addresses.

Is there a way to do the same thing in Perl so that I can use the aliases with Net::SMTP instead of the real email addresses?

Replies are listed 'Best First'.
Re: Net::SMTP and resolving an alias
by haukex (Bishop) on Aug 04, 2016 at 17:34 UTC

    Hi mdamazon,

    Although I don't have direct experience in implementing this, assuming you've got a Windows network with Active Directory, AFAIK it can be queried with Net::LDAP. You could try, for example, the code provided in this article: Reading from LDAP in Perl using Net::LDAP.

    Update: By the way, other modules like Email::Simple and Email::Sender provide a somewhat easier-to-use and more modern interface to sending mail than using Net::SMTP.

    Hope this helps,
    -- Hauke D

Re: Net::SMTP and resolving an alias
by Marshall (Canon) on Aug 04, 2016 at 15:47 UTC
    I don't use Outlook, but I did find Mail::Outlook. The "all_accounts" method looks promising. So perhaps you could just ask Outlook who it knows about? The aliases may be in the account object. Otherwise, I guess you could build your own alias table. I am not aware of any DB that Net::SMTP would have access to. Keep in mind that the alias may not resolve to a unique email address. Example when I'm sending email, I type in "Tom" and then get a list for me to pick the "right" Tom.

    Update: I did a google search export+outlook+address+book. Evidently there is a way to export the address book as a .CSV file. Since I don't have Outlook, I don't know exactly what is in there or what that would mean on a corporate network vs standalone Outlook or Outlook Express. Just an idea that may or may not help.

Re: Net::SMTP and resolving an alias
by neilwatson (Priest) on Aug 04, 2016 at 15:27 UTC

    Outlook simply looks up previously entered email addresses, and it can pick the wrong on. It has no knowledge of what an email, smtp, server may know.

    No, I don't think you can make Perl query the smtp server for email addresses; that would be a security risk.

    Neil Watson

      neilwatson - My understanding is that outlook will also do a search on the email server (whichever configured at the setup) when you put a partial name of the person and press CTRL+K.

      If you type Anthony and press CTRL+K, it will use all email addresses containing the name Anthony along with the previously used ones.

      The one you are referring is called Outlook Caching and as long as you have that enabled in your preferences, then the previously used emails are cached. The moment you compose a new email and start typing the name, it will appear automatically for you to select. I just wanted to share this piece of information.

      NOTE: This is very much applicable in a lot of corporate companies where they have dedicated email server which contains all their employee emails. Not applicable to Yahoo, Gmail,etc

        What you describe is not SMTP. Exchange has an SMTP service, but Exchange is so much more. Any queries to Exchange for addresses would be a different protocol.

        Neil Watson

Re: Net::SMTP and resolving an alias
by jesuashok (Curate) on Aug 05, 2016 at 06:01 UTC
    You can write an API to connect to your corporate directory and populate the list accordingly.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1169126]
Approved by Marshall
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2020-11-29 02:27 GMT
Find Nodes?
    Voting Booth?

    No recent polls found