我目前正在使用网络服务,如果发生错误或发送的数据格式不正确,该服务必须向客户回复电子邮件。我正在使用MAPIMessage类发送在运行该服务的计算机中打开的任何 Microsoft Outlook 帐户中设置为“未读”的邮件。
这是发送电子邮件的方法的代码。
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;
}
}
就像我之前说的,这封邮件只能是纯文本,所以我将最后两个参数设置为 null 以指定该方法在我回复邮件时没有任何附件:
EnviarMail(someCustomerEmail, "", "", Properties.Resources.SomeSubject, someBodyText, null, "");
事实上,这封电子邮件包含文件 winmail.dat,这不是我想要的。这是通过在 gmail 帐户中测试的外观: