internal static void Send(MailMessage message) { // create message object Object m = _helper.CreateInstance(); // set properties if (message.From != null) { _helper.SetProp(m, "From", message.From); } if (message.To != null) { _helper.SetProp(m, "To", message.To); } if (message.Cc != null) { _helper.SetProp(m, "Cc", message.Cc); } if (message.Bcc != null) { _helper.SetProp(m, "Bcc", message.Bcc); } if (message.Subject != null) { _helper.SetProp(m, "Subject", message.Subject); } if (message.Priority != MailPriority.Normal) { String importance = null; switch (message.Priority) { case MailPriority.Low: importance = "low"; break; case MailPriority.Normal: importance = "normal"; break; case MailPriority.High: importance = "high"; break; } if (importance != null) { SetField(m, "importance", importance); } } if (message.BodyEncoding != null) { Object body = _helper.GetProp(m, "BodyPart"); LateBoundAccessHelper.SetPropStatic(body, "Charset", message.BodyEncoding.BodyName); Marshal.ReleaseComObject(body); } if (message.UrlContentBase != null) { SetField(m, "content-base", message.UrlContentBase); } if (message.UrlContentLocation != null) { SetField(m, "content-location", message.UrlContentLocation); } int numHeaders = message.Headers.Count; if (numHeaders > 0) { IDictionaryEnumerator e = message.Headers.GetEnumerator(); while (e.MoveNext()) { SetField(m, (String)e.Key, (String)e.Value); } } if (message.Body != null) { if (message.BodyFormat == MailFormat.Html) { _helper.SetProp(m, "HtmlBody", message.Body); } else { _helper.SetProp(m, "TextBody", message.Body); } } for (IEnumerator e = message.Attachments.GetEnumerator(); e.MoveNext();) { MailAttachment a = (MailAttachment)e.Current; Object bodyPart = _helper.CallMethod(m, "AddAttachment", new Object[3] { a.Filename, null, null }); if (a.Encoding == MailEncoding.UUEncode) { _helper.SetProp(m, "MimeFormatted", false); } if (bodyPart != null) { Marshal.ReleaseComObject(bodyPart); } } // optional SMTP server String server = SmtpMail.SmtpServer; if (server.Length == 0) { server = null; } if (server != null || message.Fields.Count > 0) { Object config = LateBoundAccessHelper.GetPropStatic(m, "Configuration"); if (config != null) { if (server != null) { LateBoundAccessHelper.SetPropStatic(config, "Fields", "http://schemas.microsoft.com/cdo/configuration/sendusing", (Object)2); LateBoundAccessHelper.SetPropStatic(config, "Fields", "http://schemas.microsoft.com/cdo/configuration/smtpserver", server); LateBoundAccessHelper.SetPropStatic(config, "Fields", "http://schemas.microsoft.com/cdo/configuration/smtpserverport", (Object)25); } foreach (DictionaryEntry e in message.Fields) { LateBoundAccessHelper.SetPropStatic(config, "Fields", (String)e.Key, e.Value); } Object fields = LateBoundAccessHelper.GetPropStatic(config, "Fields"); LateBoundAccessHelper.CallMethodStatic(fields, "Update", new Object[0]); Marshal.ReleaseComObject(fields); Marshal.ReleaseComObject(config); } } // send mail _helper.CallMethod(m, "Send", new Object[0]); // close unmanaged COM classic component Marshal.ReleaseComObject(m); }
internal static void Send(MailMessage message) { // create mail object Object newMail = _helper.CreateInstance(); // set properties if (message.From != null) { _helper.SetProp(newMail, "From", message.From); } if (message.To != null) { _helper.SetProp(newMail, "To", message.To); } if (message.Cc != null) { _helper.SetProp(newMail, "Cc", message.Cc); } if (message.Bcc != null) { _helper.SetProp(newMail, "Bcc", message.Bcc); } if (message.Subject != null) { _helper.SetProp(newMail, "Subject", message.Subject); } if (message.Priority != MailPriority.Normal) { int p = 0; switch (message.Priority) { case MailPriority.Low: p = 0; break; case MailPriority.Normal: p = 1; break; case MailPriority.High: p = 2; break; } _helper.SetProp(newMail, "Importance", p); } if (message.BodyEncoding != null) { _helper.CallMethod(newMail, "SetLocaleIDs", new Object[1] { message.BodyEncoding.CodePage }); } if (message.UrlContentBase != null) { _helper.SetProp(newMail, "ContentBase", message.UrlContentBase); } if (message.UrlContentLocation != null) { _helper.SetProp(newMail, "ContentLocation", message.UrlContentLocation); } int numHeaders = message.Headers.Count; if (numHeaders > 0) { IDictionaryEnumerator e = message.Headers.GetEnumerator(); while (e.MoveNext()) { String k = (String)e.Key; String v = (String)e.Value; _helper.SetProp(newMail, "Value", k, v); } } if (message.BodyFormat == MailFormat.Html) { _helper.SetProp(newMail, "BodyFormat", 0); _helper.SetProp(newMail, "MailFormat", 0); } if (message.Body != null) { _helper.SetProp(newMail, "Body", message.Body); } for (IEnumerator e = message.Attachments.GetEnumerator(); e.MoveNext();) { MailAttachment a = (MailAttachment)e.Current; int c = 0; switch (a.Encoding) { case MailEncoding.UUEncode: c = 0; break; case MailEncoding.Base64: c = 1; break; } _helper.CallMethod(newMail, "AttachFile", new Object[3] { a.Filename, null, (Object)c }); } // send mail _helper.CallMethod(newMail, "Send", new Object[5] { null, null, null, null, null }); // close unmanaged COM classic component Marshal.ReleaseComObject(newMail); }