Block email sender - c#

Is there anyway you can create a code, when you click a button (I've already created this) it will take the selected email and block the sender which will delete the email?

The Outlook object model doesn't provide anything for that. However you can create a VSTO add-in which can handle incoming emails and delete them is the sender belongs to a blocked list. The NewMailEx event of the Application class is fired when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously.
See Walkthrough: Create your first VSTO Add-in for Outlook to get started quickly.

Outlook Object Model does not expose blocked/safe senders at all.
If using Redemption (I am its author) is an option, it exposes RDOJunkEmailOptions object (returned from RDOSession.JunkEmailOptions, RDOAccount.JunkEmailOptions, RDOExchangeMailboxStore.JunkEmailOptions), which allow to add blocked senders using RDOJunkEmailOptions.BlockedSenders.Add.

Related

Getting the actual sender's "sent items" folder in Office 365 Outlook (c#)

My earlier problem about catching an email message just after it has sent was resolved by using the Items.ItemAdd event handler of the Sent Items folder. This works fine when I don't change the sender mailbox. But if I change it by selecting some other account from the dropdown list of the sender on the interface shown by mailItem.Display(true); , then the sent message lands in the "sent items" folder of this other account, but
Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
doesn't change accordingly, so in this way I can't catch the message. How could I get the "sent items" folder of the selected (not default) sender?
(an acceptable workaround would be to change the default mailbox, but I also don't know how to do this).
The GetDefaultFolder method of the Store class returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.
You can to handle the ItemSend event of the Application class where you can get the sender. Then you can find associated store and use the GetDefaultFolder method to get the correct Sent Items folder.
Be aware, the SaveSentMessageFolder property of the MailItem class returns or sets a Folder object that represents the folder in which a copy of the e-mail message will be saved after being sent (instead of the Sent Items folder).

Email sent with Outlook Object Model stays in Outbox until I start Outlook

I'm trying to send emails from a .NET application using Outlook Object Model.
My application displays the Outlook message window so the user can see what we're sending and edit it first. When the user hits the Send button, the Outlook window closes, and the message gets sent. This works perfectly as long as the Outlook application is already running.
If the Outlook application isn't already running, the message gets stuck in the Outbox, and will not send until I start Outlook. When I start Outlook, I can see the message sitting in the Outbox folder for a few seconds, then it gets sent.
Here is a simplified version of the code I'm using to send the email:
Outlook.Application app = new Outlook.Application();
var ns = app.GetNamespace("MAPI");
// (ref: https://msdn.microsoft.com/en-us/library/office/ff861594.aspx)
// If outlook is already running, this does nothing. If it isn't, this has the
// side-effect of initializing MAPI to use the default profile and make the object
// model fully functional
var mailFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
var mailItem = (Outlook.MailItem)ns.Application.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.To = "me#nowhere.com";
mailItem.Subject = "This is a test";
mailItem.HTMLBody = "<html>A bunch of HTML</html>";
mailItem.Display(true);
NOTE: If I replace the call to mailItem.Display() with mailItem.Send(), it works whether Outlook is running or not. Unfortunately that's not an option, because I need the user to be able to edit the message before sending it.
I'm thinking I need a way to detect when the message has finished sending, and keep the Outlook.Application object alive until then...but I'm not sure how to do that. My app is a console application that needs to exit after sending the email. Putting the thread to sleep for awhile doesn't do it (probably because whatever I'm waiting for is happening on that same thread).
Outlook will exit if no more windows (explorers or inspectors) are open or referenced.
Reference an inspector object, retrieve the first SyncObject object from Namespace.SyncObjects and wait for the SyncObject.SyncEnd event to fire.
insp = mailItem.GetInspector;
insp.Display(true);
//keep insp referenced

Bypass/Ignore Exchange Server "Maximum Send Size"?

As soon as possible I will start a bounty and award 150 (that's what I have) points for solution.
I am developing Outlook add in. When message is sent, add in processes the message, it removes the attachments and sends them through different transfer channel and puts the attachment download links in message body.
When using outlook with exchange server with "maximum send size" limit users can't even attach large files to message. Outlook displays a warning that imposes exchange limit.
To make it worse attachment is refused before any of attachment events are fired.
I need a way to bypass this behavior. Something that will allow users to add attachments of any size by using outlook paper clip button, or drag and drop. Or good direction I can work on.
Adding separate attach button is not an option.
Try to set the PR_MAX_SUBMIT_MESSAGE_SIZE MAPI property (DASL name http://schemas.microsoft.com/mapi/proptag/0x666D0003) using Store.PropertyAccessor.SetProperty.
I was able to set it using OutlookSpy (I am its author) - click IMsgStore button, right click, select IMAPIProp::GetProps, type PR_MAX_SUBMIT_MESSAGE_SIZE - the property is not shown by default, then double click to modify it. I don't know if Outlook will overwrite it on the local cached store later - I never tried to set that property.
Note that the limit is there for a reason - Exchange won't let you send the message if it is over the limit. But it will work if you simply want to get rid of the warming because you will handle the attachment on your own when the message is sent.
You cannot do this, by design. The limit is enforced in the message store to which the submit operation is sent. You could zip the attachment, or chunk it up into separate emails, to allow very large data to be sent.

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

windows live mail mapi support

I am writing a c# .net application that needs to send email messages using MAPI. I am using the following library to achieve this http://www.codeproject.com/KB/IP/SendFileToNET.aspx
Here is an example how I use it.
MAPI mapi = new MAPI();
mapi.AddRecipientTo("test#test.com");
int returncode = mapi.SendMailPopup("subject", "message");
if(returncode==0)
{
MessageBox.Show("User sent message");
}
else if (returncode==1)
{
MessageBox.Show("User abort");
}
This piece of code opens a new message dialog on default mail program and should display if user decided to send or abort sending the email.
This code works fine when using Outlook meaning that it popups a new email dialog and returns the correct error code if user for example decides not to send the message by closing the message dialog.
The problem is that when using windows mail this does not work correctly. The send mail dialog opens correctly and the application pauses its execution on mapi.SendMailPopup until the mail dialog is closed. However no matter what the user does the mapi.SendMailPopup always return zero. If user would for example decide to close the message dialog without sending the message the mapi.SendMailPopup returns 0 when the correct response would be 1(user abort).
My question is should windows live mail have required MAPI-support for this, and if no can someone tell me some other free windows mail client that would offer the required MAPI-support
This is confusing-- that .NET solution is SMAPI, not MAPI. I'm not sure how reliable the return values from SMAPI are, especially since the return value is returned directly from your default MUA vendor's implementation of SMAPI, and there are at least a dozen of them out there. Since the browser doesn't use the return value, and they're the principal clients of SMAPI, I wouldn't rely on it.

Categories