I'm currently working with a web service which has to reply an email to the customers if some error happens or if the data sent is not in the correct format. I'm using the class MAPIMessage to send mails maked as "unread" in any Microsoft Outlook account opened in the computer which runs the service.
This is the code of the method which sends the emails.
private void EnviarMail(string destinatarios, string CC, string BCC, string asunto, string texto, byte[] buffer, string nombreArchivo)
{
if (string.IsNullOrEmpty(destinatarios))
throw new ArgumentNullException("destinatarios", "El destinatario de correo no puede estar vacío");
try
{
if (_mapi.OpenOutbox())
{
MAPIMessage message = new MAPIMessage();
if (message.Create(_mapi, MAPIMessage.Priority.IMPORTANCE_NORMAL))
{
message.SetSenderName(Settings.Default.Remitente);
message.SetSenderEmail(Settings.Default.RemitenteCorreo);
message.SetSubject(asunto);
message.SetBody(texto);
foreach(string destinatario in destinatarios.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries))
message.AddRecipient(destinatario.Trim());
//some other code irrelevant for the question
if (buffer != null)
{
//doesn't matter right now
}
if (!message.Send())
throw new ApplicationException("No pudo enviarse el correo electrónico.");
}
}
}
catch
{
throw;
}
}
Like I said before, this mail has to be only plain text, so I set the last two parameters as null in order to specify that the method doesn't have any attachment when I reply the message:
EnviarMail(someCustomerEmail, "", "", Properties.Resources.SomeSubject, someBodyText, null, "");
The fact is that this email includes the file winmail.dat and this is not what I want. This is how it looks by testing in a gmail account: