Getting email provider from email address - email

I'm trying to get the email provider (ex: gmail,outlook,yahoo) from any email address so that i can use specific smtp settings to avoid my messages being listed as spam.
My current approach is parsing the mail server potion of the email address and using that as the identifier but email providers have multiple mail servers (ex: outlook has outlook.com but also live.ca).
Any suggestions of a simple approach to identifying the mail provider? If there is any method using PHP that would be especially desirable. Any help?

You can use a map for mapping the mail domain name (that you obtain after parsing the e-mail address) to the mail provider:
$providerMap = array(
"gmail" => "Gmail"
"outlook" => "Outlook"
"live" => "Outlook"
# etc...
);
Then, you can use it like this:
$providerDomain = getDomain($emailAddress); // assuming getDomain() is the function that parses an email address and returns
echo "The provider is: $providerMap[$providerDomain]"
P.S.: You may want to think about how to handle the case where the email address domain name doesn't match any provider. You can:
Throw an exception/display an error message
Add a functionality allowing an authorised user to add a new provider (i.e. for adding a new entry in the map)
...

Related

Sending bounce e-mails to the "header from" address

I want the bounced messages are delivered to "Header From" instead of "Header ReturnPath". See Case 2 below. Here is the setup:
Envelop
RFC5321.MailFrom
RFC5321.RcptTo
Header
RFC5322.From
RFC5322.To
RFC5322.ReturnPath (injected from RFC5321.MailFrom)
Case 1: RFC5322.From is an invalid address
Current Behaviour: "rejected" NDR report is send to RFC5322.ReturnPath, which is originally RFC5321.MailFrom.
=> OK; must be keep unchanged.
Case 2: E-mail cannot be delivered to "RFC5322.To"
Current behaviour: "Bounced" e-mail is send to RFC5322.ReturnPath
Wanted behaviour: "Bounced" e-mail is send to RFC5322.From
Background:
RFC5321.MailFrom is the last support e-mail address in case of any problems. It differs from RFC5322.From
RFC5322.From is the person/organization who want to take care about "bounced" e-mails, cause it is B2B business - where e-mail does contains relevant information.
How to configure the e-mail server to send "bounced" e-mails to RFC5322.From instead of RFC5322.ReturnPath?
According the messaging team the following configuration is fix:
Envelop From => returnpath AND returnpath => bounce address
I just canĀ“t believe ;-)

Mail Session settings at Websphere Server

The mails are sent with default From address as wasadm#servername which I want to change. I tried using the property mailFrom at application.inf file, changed the values at websphere console - Resources >> Mail >> Mail Sessions >> Return e-mail address but nothing worked out.
Could you please let me know if you have some solution to replace the default from mail address to a custom value.
Normally, the email-sending application code sets a "from" address in the message itself.
That said, I think it might work to set a Mail Session Custom property of mail.from. According to https://javaee.github.io/javamail/docs/api/overview-summary.html:
mail.from The return email address of the current user, used
by the InternetAddress method getLocalAddress.
I know from experience that the envelope sender address can be set with Custom property mail.smtp.from. See https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
mail.smtp.from Email address to use for SMTP MAIL command. This sets the envelope
return address. Defaults to msg.getFrom() or
InternetAddress.getLocalAddress(). NOTE: mail.smtp.user was previously
used for this.

MailKit: How to get the To email address when it is an alias

I am sending an email to alias#company.com which is an alias to a real mailbox address. I then connect to the real mailbox (let's say realmailbox#company.com) using MailKit and retrieve messages. When I inspect the To address, all I see is the realmailbox#company.com. How to I see the original alias address that the email was sent to?
For example:
var fullMessage = imapClient.Inbox.GetMessage(uid);
var recipients = fullMessage.To;
recipients only show the realmailbox#company.com, not the alias#company.com.
It sounds to me like your SMTP server is performing a string substitution on the alias before passing it along to the recipient mailbox making it impossible to get the info you are looking for.

Is username#gtld a valid email? i.e. there is no "domain" portion, it is just a TLD for the hostname

So would username#gtld be a valid email? As a practical example google is purchasing the gTLD "gmail". Obviously they can associate A records with that permitting you to just type http://gmail/ to access the site. But, are there any specs that prohibit them from associating MX records with that as well, allowing folks to give out an alternative address username#gmail?
I ask because I want to make sure our email validator is future proof and technically correct.
I think I answered my own question. Section 3.4.1 of rfc5322 which defines a valid email address states:
addr-spec = local-part "#" domain
[...]
domain = dot-atom / domain-literal / obs-domain
[...]
The domain portion identifies the point to which the mail is delivered. In the dot-atom form, this is interpreted as an Internet domain name (either a host name or a mail exchanger name) as described in [RFC1034], [RFC1035], and [RFC1123]. In the domain-literal form, the domain is interpreted as the literal Internet address of the particular host.
"gmail" would be a valid domain and host name and thus someone#gtld is a valid email address.

Send email to address alternate from "To:"

I am implementing a sort of dynamic mailing-list system in Rails. I am looking to basically send an email and have the recipient receive it in this form:
From: person#whosentthis.com
To: mailing-list#mysite.com
<body>
Basically, the challenge is how do I send an email to an address while defining a different To: header so that they can easily reply to the mailing list or just the original sender?
Mail vs. Envelope
In emails as in physical mails (paper sheet in paper envelope), the recipient on the envelope may differ from the recipient on the letter sheet itself.
As the mailman would only consider the envelope's recipient, so do mail servers.
That means, one actually can tell the smtp service to send and email to a recipient different than the one listed in the To: field of the emails header.
Trying This Out Manually
You can try this out, manually, for example, by using the sendmail command of postfix.
# bash
sendmail really_send_to_this_address#example.com < mail.txt
where
# mail.txt
From: foo#example.com
To: this_will_be_seen_in_the_to_field_in_email_clients#example.com
Subject: Testmail
This is a test mail.
This will deliver the email to really_send_to_this_address#example.com, not to this_will_be_seen_in_the_to_field_in_email_clients#example.com, but the latter will be shown in the recipient field of the mail client.
Specifying the Envelope_to Field in Rails
The ActionMailer::Base internally uses the mail gem. Currently, Apr 2013, there is a pull request, allowing to specify the envelope_to field on a message before delivery.
Until this is pulled, you can specify the fork in the Gemfile.
# Gemfile
# ...
gem 'mail', git: 'git://github.com/jeremy/mail.git'
You need to run bundle update mail after that, and, depending on your current rails version, maybe also bundle update rails in order to resolve some dependency issues.
After that, you can set the envelope recipient of a mail message like this:
# rails
message # => <Mail::Message ...>
message.to = [ "this_will_be_seen_in_the_to_field_in_email_clients#example.com" ]
message.smtp_envelope_to = [ "really_send_to_this_address#example.com" ]
message.from = ...
message.subject = ...
message.body = ...
message.deliver
Documentation
https://github.com/mikel/mail/pull/477
http://rubydoc.info/github/jeremy/mail/master/Mail/Message#smtp_envelope_to%3D-instance_method
https://github.com/mikel/mail
Why not use the BCC header for this? Put person#whoshouldreceivethis.com into BCC and mailing-list#mysite.com into TO.
Clearification:
There is no technical solution for this. The email headers do what they do, you can't influence them in that once the email is on the way.
I am sure, though, you can find a combined use of TO, CC, BCC and REPLY-TO that gives you what you want.