I have been getting the sender's email address in Outlook using the RDOMail.SenderEmailAddress property, but I have recently realised that under some cases for SMTP or IMAP email accounts, that this property is null occasionally, right after the email arrives the inbox.
There's a rather convoluted way to get the sender's email address using the Outlook Interop Library: https://msdn.microsoft.com/library/office/ff184624.aspx
However, this does not work with the Redemption RDOMail object because the RDOAddressEntry interface lacks the AddressEntryUserType and the GetExchangeUser method.
The documentation of the RDOAddressEntry object says the following about the SMTPAddress property:
String, read-only. Returns the SMTP address of the given user. If the
address type is "SMTP", the returned value is the same as that
returned by the Address property. If the address type is "EX",
Redemption tries to retrieve the PR_SMTP_ADDRESS property, if
unsuccessful, it retrieves the default SMTP address from the
PR_EMS_AB_PROXY_ADDRESSES Extended MAPI property.
Looks like it might be a more reliable way to get the sender's address if I do this in my method:
if (rdoMail.SenderEmailAddress != null) return rdoMail.SenderEmailAddress;
if (rdoMail.Sender != null) return rdoMail.Sender.SMTPAddress;
return null;
Since I don't have a reliable way to test my theory, I'm seeking help here to see if anyone has more experience in dealing with this problem.
Thanks in advance.
I cannot image why SenderEmailAddress would be null, unless you have a partially downloaded item (IMAP4 specific). There is no reason to have AddressEntryUserType or GetExchangeUser method - all you need is the address type - if it is "EX", you have a GAL user, otherwise an SMTP address.
To get the sender SMTP address, check the SenderEmailType property. If it is anything but "EX", just use the SenderEmailAddress property. If it is "EX", read the PidTagSenderSmtpAddress property using RDOMail.Fields["http://schemas.microsoft.com/mapi/proptag/0x5D01001F"]. If you get back null, check if RDOMail.Sender is not null and read the RDOMail.Sender.SMTPAddress property.
Related
I want to deploy an addin to outlook 2013.
The basic principle is that if an employee send an email to a certain adress, then the addin will auto fill his body with some info he must provide.
i tried this but it won't work.
if (mailItem.To == "some#example.com")
{
mailItem.Subject = "support ticket";
mailItem.Body = "IP :[ ]";
}
When exactly does the code run? in the Application.ItemSend event? What exactly does not work? You need to be a lot more specific than that.
If it is (as I suspect) the test for the email address that is failing, you need to avoid using the To property and instead loop through the Recipients collection comparing each Recipient.Address property. If it is an Exchange mailbox, the address will be an EX type address (as opposed to SMTP) and you will need to use
`Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress`
(be prepared to handle nulls and exceptions).
Is there a way to get the primary SMTP address from an exchange account in Outlook ? I am currently using Redemption and following code keeps returning an empty value.
> IRDOExchangeAccount exAcc = (IRDOExchangeAccount)rdoAcc;
> string email = exchangeAccount.CurrentUser.SMTPAddress;
Currently I am using
exchangeAccount.CurrentUser.Address
property to get the Email and seems it gets me the correct Email address. How reliable that property is ? Is there another better way ?
I am currently evaluating the redemption library for converting MSG files to EML files.
RDOSession session = new RDOSession();
RDOMail msg = session.GetMessageFromMsgFile(msgFile);
msg.SaveAs(emlFile, rdoSaveAsType.olRFC822);
So far Redemption is doing a really good job here in contrast to everything else I've tested against our "wild MSG-files corpus".
Nevertheless there is an issue with internal e-mail addresses. For internal e-mail addresses the resulting EML-file does contain the personal part of the addresses only but not the real e-mail address with the # sign.
I can see that RDOMail's recipient objects contains the real e-mail address in the SMTPAddress property in any case.
But there is a difference for the Address property which contains the "real e-mail address" for external addresses but something like /O=EXAMPLE ORGANIZAION/OU=SOME GROUP/cn=Recipients/cn=FBarney for internal addresses.
The latter ones are exactly the addresses that are missing the real e-mail address in the resulting EML-file.
So I tried to override the Address property like that:
recipient.Address = recipient.SMTPAddress;
But this does not have any effect on the resulting EML-file at the end.
How to convert MSG to EML with redemption without losing the real e-mail addresses for internal addresses?
This is an indication that EX type addresses cannot be converted to SMTP. This usually happens if the current MAPI session does not have access to the Exchange server that hosts these GAL objects. In your particular case, there is no MAPI session at all. You can either set the RDOSession.MAPIOBJECT property to Namespace.MAPIOBJECT from the Outlook Object Model to share the session with Outlook or you can call RDOSession.Logon/LogonExchangeMailbox/etc.
You can also try to specify the olRfc822_Redemption format to force Redemption to use its internal MIME convertor (it jumps through quite a few hoops to get the SMTP addresses from the message itself rather than GAL). By default olRfc822 uses the built-in Outlook convertor (IConvertorSession) if Outlook is installed.
I am using Exchange Web Services trying to find the Organizer of the meeting's email address
I have tried using
Appoint.Organizer.Address
but some of the properties are null (see image).
How do I get the email address of the organizer?
Link to image (sorry not enough rep to embed)
http://i.stack.imgur.com/wSv2r.png
What operation are you using ? If you have just used FindItems then that's what you would expected because only the displayName of the Sender (which is the Organizer) is returned with FindItems. To get the Address property populated you would need to do a GetItem (or Load in the Managed API).Or if you really want to save a call you could try using the PidTagSenderSmtpAddress extended property http://msdn.microsoft.com/en-us/library/office/jj713594(v=office.15).aspx
Cheers
Glen
Do you know how this meeting came into the mailbox? Was it sent from a sender outside of Exchange, or another mailbox in that Exchange organization? What version of Exchange? Also how are you binding to the appointment? It would be good to see that code. I've tried this with a few meetings here and they all have the Address property populated. Your screenshot shows a MailboxType field of "OneOff", and I'm not sure off the top of my head how to make that happen.
Typically "OneOff" refers to a recipient that couldn't be resolved. In this case, you might try taking the information that is present (in this case the display name) and calling ResolveName to see if you can get the address that way.
From an AddressEntry instance I'm calling GetExchangeUser or GetExchangeDistributionList methods to get PrimarySmtpAddress. This works fine when the AddressEntry has a DisplayType of olUser or olDistList, but both return null for an address with DisplayType of olForum.
The Exchange address does have an associated SMTP address. In Outlook I can type the address into "To" on a new email and it resolves to the appropriate Exchange user. Double-click on the user and an SMTP address does show. I just can't find a way to get to it through the Outlook object model.
If the SMTP address is available on that address entry, you should be able to retrieve it using AddressEntry.PropetyAccessor.GetProperty.
Take a look at that address entry using OutlookSpy (I am its author) - if you already have a message with that GAL entry as one of the recipients, select it in Outlook, click IMessage button on the OutlookSpy ribbon, go to the GetRecipientTable tab, double click on the recipient.
Do you see PR_SMTP_ADDRESS property? How about PR_EMS_AB_PROXY_ADDRESSES? Both properties can be retrieved using AddressEntry.PropetyAccessor.GetProperty