Dart.Mail Namespace : Resource Class |
/// <summary> /// Saves the email's resources (files intended for display within the HTML /// message body) to the specified directory. /// </summary> /// <param name="message">MailMessage containing resources to save.</param> /// <param name="saveDirectory">Directory to save resources to.</param> private void SaveResources(MailMessage message, string saveDirectory) { foreach (Resource res in message.Resources) { string filePath = Path.Combine(saveDirectory, res.ContentType.Name); using (FileStream fs = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write)) fs.Write(res.Content, 0, res.Content.Length); } }
''' <summary> ''' Saves the email's resources (files intended for display within the HTML ''' message body) to the specified directory. ''' </summary> ''' <param name="message">MailMessage containing resources to save.</param> ''' <param name="saveDirectory">Directory to save resources to.</param> Private Sub SaveResources(ByVal message As MailMessage, ByVal saveDirectory As String) For Each res As Resource In message.Resources Dim filePath As String = Path.Combine(saveDirectory, res.ContentType.Name) Using fs As New FileStream(filePath, FileMode.CreateNew, FileAccess.Write) fs.Write(res.Content, 0, res.Content.Length) End Using Next res End Sub
private MailMessage getMessageFromHtml(string pathToHtml, string pathToHtmlResources, string from, string to, string subject, bool includeTextPlain) { //Note: to load a .mht (Mime HTML) file, use MailMessage.Open() instead. //Load HTML string html; using (StreamReader sr = new StreamReader(pathToHtml)) html = sr.ReadToEnd(); //Initialize a MailMessage object. includeTextPlain controls whether the message should include a text/plain part //(which determines whether the message is multipart/alternative (when true) or multipart/related (when false)) string textPlain = (includeTextPlain) ? "text/plain representation of included HTML" : null; MailMessage mailMsg = new MailMessage(textPlain, html, new DirectoryInfo(pathToHtmlResources).GetFiles()); //Set sender, recipients and subject mailMsg.From = from; mailMsg.To = to; mailMsg.Subject = subject; return mailMsg; }
Private Function getMessageFromHtml(ByVal pathToHtml As String, ByVal fromAddress As String, ByVal toAddress As String, ByVal subject As String) As MailMessage 'Note: to load a .mht (Mime HTML) file, use MailMessage.Open() instead. 'Load HTML Dim sr As New StreamReader(pathToHtml) Dim html As String = sr.ReadToEnd() sr.Close() 'Initialize a MailMessage object. includeTextPlain controls whether the message should include a 'text/plain part (which determines whether the message is multipart/alternative (when true) or multipart/related (when false)) Dim textPlain As String = If(includeTextPlain, "text/plain representation of included HTML", Nothing) Dim mailMsg As New MailMessage(textPlain, html, New DirectoryInfo(pathToHtmlResources).GetFiles()) 'Set sender, recipients and subject mailMsg.From = fromAddress mailMsg.To = toAddress mailMsg.Subject = subject Return mailMsg End Function
System.Object
Dart.Mail.Part
Dart.Mail.Resource
Dart.Mail.Attachment
Dart.Mail.Messagepart
Dart.Mail.Textpart