public CDOMessageConverter(string mailContent) { cdoMessage = new CDO.Message(); ADODB.Stream adoStream = cdoMessage.GetStream(); adoStream.Type = ADODB.StreamTypeEnum.adTypeText; adoStream.WriteText(mailContent.Trim(), ADODB.StreamWriteEnum.adWriteLine); adoStream.Flush(); adoStream.Close(); }
/// <summary> /// Sends the email MHTML. /// </summary> /// <param name="message">The message.</param> public virtual void SendMhtml(MailMessage message) { lock (_lock) try { var m = new CDO.Message(); // set message var s = new ADODB.Stream(); s.Charset = "ascii"; s.Open(); s.WriteText(message.Body); m.DataSource.OpenObject(s, "_Stream"); // set configuration var f = m.Configuration.Fields; switch (DeliveryMethod) { case SmtpDeliveryMethod.Network: f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPort; f["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = Host; break; case SmtpDeliveryMethod.SpecifiedPickupDirectory: f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPickup; f["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"].Value = PickupDirectoryLocation; break; default: throw new NotSupportedException(); } f.Update(); // set other values m.MimeFormatted = true; m.Subject = message.Subject; if (message.From != null) m.From = message.From.ToString(); var to = (message.To != null ? string.Join(",", message.To.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) m.To = to; var bcc = (message.Bcc != null ? string.Join(",", message.Bcc.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) m.BCC = bcc; var cc = (message.CC != null ? string.Join(",", message.CC.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) m.CC = cc; if (message.Attachments != null) foreach (var attachment in message.Attachments.Where(x => x != null)) AddAttachement(m, attachment, false); m.Send(); } catch (Exception ex) { throw ex; } }
/// <summary> /// Sends the email MHTML. /// </summary> /// <param name="message">The message.</param> public virtual void SendMhtml(MailMessage message) { lock (_lock) try { var m = new CDO.Message(); // set message var s = new ADODB.Stream(); s.Charset = "ascii"; s.Open(); s.WriteText(message.Body); m.DataSource.OpenObject(s, "_Stream"); // set configuration var f = m.Configuration.Fields; switch (DeliveryMethod) { case SmtpDeliveryMethod.Network: f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPort; f["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = Host; break; case SmtpDeliveryMethod.SpecifiedPickupDirectory: f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPickup; f["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"].Value = PickupDirectoryLocation; break; default: throw new NotSupportedException(); } f.Update(); // set other values m.MimeFormatted = true; m.Subject = message.Subject; if (message.From != null) { m.From = message.From.ToString(); } var to = (message.To != null ? string.Join(",", message.To.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) { m.To = to; } var bcc = (message.Bcc != null ? string.Join(",", message.Bcc.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) { m.BCC = bcc; } var cc = (message.CC != null ? string.Join(",", message.CC.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) { m.CC = cc; } if (message.Attachments != null) { foreach (var attachment in message.Attachments.Where(x => x != null)) { AddAttachement(m, attachment, false); } } m.Send(); } catch (Exception ex) { throw ex; } }