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

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.

Related

Forward Emails preserving recipients (INDY and Delphi)

I retrieve eMails from a GMail account with a TIdIMAP4-object and want to forward them with TIdSMTP to an other (GMail-)account while preserving the original list of recipients.
My approach was adding the destination address as BCC to make it invisible in the destination, but how can I prevent the SMTP component from sending it to all the other recipients in the list? They then would get all the forwarded mails twice.
UPDATE 1:
Instead of using BCC I provided the destination address in the send statement
smtp.Send(msg,destination);
but the message is still sent to all the other recipients.
By default, TIdSMTP.Send() will send the email to all of the recipients listed in the Recipients, CcList and BccList properties of TIdMessage.
When you download an email into a TIdMessage via POP3 or IMAP, the Recipients and CcList (but not the BccList) are filled in from the email's existing To and CC headers, respectively.
When you then forward the email, if you do not want it to be sent to the recipients specified in the email, then you can call the overloaded version of TIdSMTP.Send() that takes a recipient list as a parameter. That will send the email ONLY to that list. For example:
var
forwardTo: TIdEmailAddressList;
begin
...
forwardTo := TIdEmailAddressList.Create;
try
// add desired recipients to forwardTo as needed, then...
smtp.Send(msg, forwardTo);
finally
forwardTo.Free;
end;
...
end;

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.

Getting email provider from email address

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)
...

Sending EMails with Indy with multiple CCs. If one is incorrect nobody recieves the mail

I currently setting up a little tool for my company that is used to send info-mails to specific user groups.
But if one or more email addresses are incorrect (missing letter etc.) I get following error and the email isn't sent at all:
EIdSMTPReplyError
Requested action not taken: mailbox unavailable
invalid DNS MX or A/AAAA resource record
I set up the email like this:
adding the first email as main recipient
adding all others to the cclist
Is there a way to set up the email so atleast the other recipients are getting the email?
Some Infos:
Delphi 7
Indy 10
Thanks in advance <3
TIdSMTP has an OnFailedRecipient event:
type
TIdSMTPFailedRecipient = procedure(Sender: TObject; const AAddress, ACode, AText: String;
var VContinue: Boolean) of object;
AAddress is the email address, and ACode and AText contain the error details.
If VContinue is set to True (the default when OnFailedRecipient is assigned), the failed email is skipped and the next recipient is attempted.
The EIdSMTPReplyError exception is raised if either:
OnFailedRecipient is not assigned when a recipient fails.
VContinue is set to False.
all recipients fail, regardless of OnFailedRecipient.

Extract ALL e-mails from GMAIL, GROUP and SORT by frequency contacted

I want to extract all e-mail addresses from GMAIL and GROUP and SORT by the email address. The result is a sorted list of email addresses I contact the most.
After some Googling
I have tried to export contacts (there is an option to select most contacted) - but this resulted in 20 most contacted. Does seem Gmail is counting ...
There is a script by labnol that exports ALL e-mail adresses ... but this is rather slow & does not do the count
question: How can I extract all e-mail addresses from GMAIL and GROUP and SORT by the email address?
Would an export to IMAP work (and count from there)? or is there a smarter way
Many thanks
You have two options
You can indeed extract headers (just headers, you don't need the full message body) from IMAP.
You can use the Gmail API. If you want to count who sends you messages, something like this should work.
Sample code using Gmail API in Python
# Retrieve a page of threads
threads = gmail_service.users().threads().list(userId='me',fields='threads(id)').execute()
# Print ID for each thread
pp = pprint.PrettyPrinter(depth=5)
if threads['threads']:
for thread in threads['threads']:
print 'Thread ID: %s has messages from senders:' % (thread['id'])
t = gmail_service.users().threads().get(userId='me',id=thread['id'],fields='messages/payload/headers').execute()
for msg in t['messages']:
for header_from in [v for v in msg['payload']['headers'] if v['name'] == 'From']:
# There should be only one, but sometimes From is missing
from_field_val = header_from['value']
print from_field_val
# TODO Extract email address and increment count
https://gist.github.com/regisd/3b4733e974483d7994fe