windows live mail mapi support - c#

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.

Related

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

Sent email from the program

I already created the application in windows forms c# which ready to be use by another user in another computer, but i am aware there will be an error occurred when run my program (because i didn't have enough time to check everything), so i decided to let users find the bug and report to me through email.
I have a button "Report a Problem", but how do i when users click that button, it will open the Microsoft Outlook and automatically filled up the Received Email or "To" with my own email?
I would suggest:
Process.Start("mailto:your#emailaddress.com");
This will prompt Windows to create a new mail using the default email provider (which will most likely be Microsoft Outlook if it's installed).
To use this method, please add:
using System.Diagnostics;
to the top of your code file.
Use Diagnostics.Process.Start("mailto: senderEmail")
And it'll work only if you have outlook as your default email client
Namespace : using System.Diagnostics;
Process.Start("mailto:revanayyamca#gmail.com");

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.

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

Generate an e-mail to be downloaded by client and sent from their outlook account

One of the requirements for the application that I'm working on is to enable users to submit a debugging report to our helpdesk for fatal errors (much like windows error reporting).
I've been told that e-mails must come from a client's mail account to prevent the helpdesk getting spammed and loads of duplicate calls raised.
In order to achieve this, I'm trying to compose a mail message on the server, complete with a nice message in the body for the helpdesk and the error report as an attachment, then add it to the Response so that the user can download, open and send it.
I've tried, without success, to make use of the Outlook Interoperability Component which is a moot point because I've discovered in the last 6 hours of googling that creating more than a few Application instances is very resource intensive.
If you want the user to send an email client side, I don't see how System.Net.Mail will help you.
You have two options:
mailto:support#domain.com?subject=Error&body=Error message here...
get user to download email in some format, open it in their client and send it
Option 1 will probably break down with complex bodies. With Option 2, you need to find a format that is supported by all mail clients (that your users use).
With option 1, you could store the email details locally on your server against some Error ID and just send the email with an Error ID in the subject:
mailto:support#domain.com?subject=Error 987771 encountered
In one of our applications the user hits the generate button and it creates and opens the email in outlook. All they have to do is hit the send button. The functions is below.
public static void generateEmail(string emailTo, string ccTo, string subject, string body, bool bcc)
{
Outlook.Application objOutlook = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));
/* Sets the recipient e-mails to be either sent by 'To:' or 'BCC:'
* depending on the boolean called 'bcc' passed. */
if (!(bcc))
{
mailItem.To = emailTo;
}
else
{
mailItem.BCC = emailTo;
}
mailItem.CC = ccTo;
mailItem.Subject = subject;
mailItem.Body = body;
mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
mailItem.Display(mailItem);
}
As you can see it is outputting the email in plaintext at the moment because it was required to be blackberry friendly. You can easily change the format to HTML or richtext if you want some formatting options. For HTML use mailItem.HTMLBody
Hope this helps.
EDIT:
I should note that this is used in a C# Application and that it is referencing Microsoft.Office.Core and using Outlook in the Email class the function is located in.
The simple answer is that what you are trying to achieve isn't realistically achievable across all platforms and mail clients. When asked to do the improbable it is wise to come up with an alternative and suggest that.
Assuming that your fault report is only accessible from an error page then you've already got a barrier to spam - unless the spammers can force an exception.
I've always handled this by logging the fault and text into the database and integrating that with a ticketing system. Maybe also have a mailto: as Bruce suggest with subject=ID&body=text to allow the user to send something by email.
I don't think an .eml format file will help either - because they'll need to forward it, and most users would probably get confused.
A .eml is effectively plain text of the message including headers as per RFC-5322.

Categories