Can't access the recipients of specific emails in Outlook - c#

I have a somewhat interesting phenomenon occurring in Outlook 2019: when we are using Exchange accounts and toggle off the "Use Cached Exchange Mode to download email to an Outlook data file" option, we are no longer able to get the e-mail addresses for recipients via the Microsoft.Office.Interop.Outlook.PropertyAccessor interface (using the MAPI property PR_SMTP_ADDRESS) from an e-mail, in which we entered the recipient e-mails using the suggested Outlook contact. (eg. when the address is entered it looks like this: 'John Smith'). When we observed the item using OutlookSpy, we noticed that the specific property's value says MAPI_E_NOT_FOUND or is not present at all. I also noticed that in these cases, Outlook puts the corresponding e-mail addresses in the BCC field, which we obviously can't access when viewing the e-mail in the recipient's inbox. Is there a way for us to get the addresses, or is there some kind of workaround for this problem?

No property is guaranteed to be present. If the property is missing, try to use Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress (error and exceptions checks omitted).

Related

Exception while reading properties of SMIME encrypted email

I'm using Outlook 2019 add-in. I need to get mail item when it is moved to Sent items folder after the email is sent. I often send SMIME encrypted or signed and encrypted emails.
When I send encrypted or signed and encrypted email to most of the recipients then I can read mail item properties (using Outlook Object Model) without problem. MessageClass in such case is IPM.Note.
However I noticed that if I send encrypted or signed and encrypted email to myself (the same email in From and To) then I can't read almost all properties. I can read some like Class, DownloadState, IsConflict, MarkForDownload, Permission, Sent, Subject, Submitted, Unred or MessageClass which in this case is IPM.Note.SMIME but for others I get exception: "Your Digital ID name cannot be found by the underlying security system."
My cert is valid and seems to be ok as encrypted emails can be sent to me from another account.
Is it Outlook bug or I can do something to make Outlook read those properties using Outlook Object Model?
I also tried to use Extended MAPI and this time I could successfully read all properties. However I prefer to use OOM and I'm also curious why I can't read all properties using OOM only in specific case.

System.Net.Mail.MailAddress does not allow Gmail GROUP contact

I am using a Gmail business account, say noreply#mycompany.com to send a daily email reports to a few of my clients whose email addresses are from different domains. I use C# to send my email to Gmail's SMTP server.
var receiver = new MailAddress("receiver#domain1.com");
var receiver = new MailAddress("receiver#domain2.com");
var receiver = new MailAddress("receiver#domain3.com");
After a while I found out I had to modify code every time a new customer demands email report. So I want to make a group and maintain that group. Gmail has a Add Group settings in your account's "Contacts" page so I used that to create a group named ReportGroup and added those people. And in the code, this lines throws exception:
var receiver = new MailAddress("ReportGroup");
saying The specified string is not in the form required for an e-mail address.
Well apparently this isn't a legit email address. Is there a way I can bypass this format check? Or is it doesn't make sense to do so?
In further attempts, I tried to name my group as reportgroup#mycompany.com. This time the email got sent without complain however the gmail server rejects the receiver, claiming that
50-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 https://support.google.com/mail/answer/6596 ai2si23882633pad.98 - gsmtp
So this isn't the way to go either. Could any one suggest a solution for me to allow someone non-programmer to maintain an receiver list to which my code sends report to?
Create an alias for your group, and then send email to that address. Then you can continue to maintain the group as you normally do.

Working with GMail Stars in ActiveUp MailSystem

I'm using ActiveUp MailSystem for an automated mail retrieve and treatment program in C# at work.
In the GMail browser mail cliente, my colleagues use GMail stars to mark a specific mail as handled or to be handled by nother colleague (they all use the same account, but some take care of some subjects while others take care of other subjects, and starring gives them a visual aid into what's taken care off and what's addressed to them by a colleague.
Using the inbox.Fetch.MessageObjectPeekWithGMailExtensions(uid) i can get which messages are starred by looking at msg.HeaderFields["x-gm-labels"] and checking it contains \Starred, however:
1 - How can i find out which start it is set to?
2 - how can i set/change a star on a particular message?
Any help is fully appreciated
I believe the Starred label only indicates that the mail can be found on the Starred mailbox. Gmail uses different IMAP mailboxes for labels. MailSystem isn't fully compatible with Gmail's enhanced IMAP commands yet (doesn't support mail's threadID for example).
You can check if IMAP actually stores the type of star by issuing a command method to the IMAP4Client class, that brings the full message (through the BODY IMAP command), but unfortunately you will have to parse and figure out the meaning of each parameter.
Other solution as Max said is using the X-GM-RAW enhanced search command to check for mails starred with the desired star, in which case you will have to use Gmail's unique identifier to know which email has which star.
Google maps stars to imap \Flagged flag, so you can just manipulate and look for that. Eg, store flag \Flagged, and the message will become starred.

How can you tell if invitations have been sent for a meeting in Outlook?

I am writing a COM add-in for Outlook using C#. If a meeting was saved and invitations were not sent, Outlook puts a message at the top of the form saying the invitations have not been sent. How do I determine programmatically that invitations have not been sent for a meeting?
I tried examining each Recipient and checking the MeetingResponseStatus. I would expect it to be OlResponseNone if the invitation has not been sent but OlResponseNotResponded if the invitations have been sent but no responses have been received. However, I always get OlResponseNone for recipients that either haven't been sent an invitation or that have but have not yet reponded. I therefore can't tell apart a meeting where invitations haven't been sent from one where they have been sent but no one has responded.
I've done most of my testing in Outlook 2007, but I believe the same holds true for 2003 and 2010, all of which I need to support.
I found a partial answer in this post. I need to read the DASL property "http://schemas.microsoft.com/mapi/id/{00020329-0000-0000-C000-000000000046}/80BE0102". In Outlook 2007 and leter, you can do this with a PropertyAccessor as follows:
appointment.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/id/{00020329-0000-0000-C000-000000000046}/80BE0102");
However, I need to also support Outlook 2003, and the PropertyAccessor property was added in Outlook 2007. I was therefore able to use Redemption's RDOMail object with the following code (error handling omitted).
var _session = New RDOSession();
_session.Logon();
var _message = _session.GetMessageFromID(appointment.EntryID, ((Outlook.MAPIFolder)appointment.Parent).StoreID);
return (bool)_message.Fields["http://schemas.microsoft.com/mapi/id/{00062002-0000-0000-C000-000000000046}/8229000B"];
Marshal.ReleaseComObject(_message);
_session.Logoff();
Marshal.ReleaseComObject(_session);

Sending an email from outlook in c#

I am following this guide and havent got very far
http://www.c-sharpcorner.com/UploadFile/casperboekhoudt/SendingEmailsThroughOutlook12052005000124AM/SendingEmailsThroughOutlook.aspx
I am getting stuck here
Now that we have the MAPI namespace,
we can log on using using:
.Logon(object Profile,
object Password, object ShowDialog,
object NewSession)
Profile: This is a string value that
indicates what MAPI profile to use for
logging on. Set this to null if using
the currently logged on user, or set
to an empty string ("") if you wish to
use the default Outlook Profile.
All i want to do from my programme is take the email address i already have in a variable and open up a new outlook email window with that email address in the too section.
Thanks very much.
This document on CodeProject shows how to open the default mail client.
http://www.codeproject.com/KB/dotnet/Default_mail_client.aspx
Check this list for common Outlook tasks.
I'm using the send attachments
It was quite easy to set up Outlook email capabilities to send reports in one of my apps following the one titled "HOW TO: Use the Microsoft Outlook Object Library to send a message that has attachments by using Visual C# .NET".
Good Luck

Categories