本文整理汇总了C#中System.Net.Mail.MailMessage.GetEmailAsString方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.GetEmailAsString方法的具体用法?C# MailMessage.GetEmailAsString怎么用?C# MailMessage.GetEmailAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailMessage
的用法示例。
在下文中一共展示了MailMessage.GetEmailAsString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadNotesAsMails
//.........这里部分代码省略.........
linkedResources.Add(lr);
}
else
{
byte[] data = Convert.FromBase64String(attachment.Base64Data);
Stream s = new MemoryStream(data);
ContentType ct = new ContentType();
ct.Name = attachment.FileName != null ? attachment.FileName : string.Empty;
ct.MediaType = attachment.ContentType != null ? attachment.ContentType : string.Empty;
System.Net.Mail.Attachment a = new System.Net.Mail.Attachment(s, ct);
attachedResources.Add(a);
}
}
htmlBody = htmlBody.Replace(@"<![CDATA[<?xml version=""1.0"" encoding=""UTF-8""?>", string.Empty);
htmlBody = htmlBody.Replace(@"<!DOCTYPE en-note SYSTEM ""http://xml.evernote.com/pub/enml2.dtd"">", string.Empty);
htmlBody = htmlBody.Replace("<en-note>", "<body>");
htmlBody = htmlBody.Replace("</en-note>]]>", "</body>");
htmlBody = htmlBody.Trim();
htmlBody = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""><head></head>" + htmlBody;
MailMessage mailMsg = new MailMessage();
AlternateView altViewHtml = AlternateView.CreateAlternateViewFromString(htmlBody, Encoding.UTF8, MediaTypeNames.Text.Html);
foreach (LinkedResource lr in linkedResources)
{
altViewHtml.LinkedResources.Add(lr);
}
// Add the alternate views instead of using MailMessage.Body
mailMsg.AlternateViews.Add(altViewHtml);
foreach (System.Net.Mail.Attachment a in attachedResources)
{
mailMsg.Attachments.Add(a);
}
mailMsg.From = new MailAddress("EveImSync <[email protected]>");
mailMsg.To.Add(new MailAddress("EveImSync <[email protected]>"));
mailMsg.Subject = n.Title;
string eml = mailMsg.GetEmailAsString();
Regex rex = new Regex(@"^date:(.*)$", RegexOptions.IgnoreCase | RegexOptions.Multiline);
eml = rex.Replace(eml, "Date: " + n.Date.ToString("ddd, dd MMM yyyy HH:mm:ss K"));
// find the folder to upload to
string tagfolder = folder;
if (n.Tags.Count > 0)
{
tagfolder = tagfolder + "/" + n.Tags[0];
}
IFolder currentFolder = GetOrCreateFolderByPath(tagfolder);
string customFlag = "xeveim" + n.ContentHash;
// now upload the new note
int numMsg = currentFolder.Messages.Length;
client.RequestManager.SubmitAndWait(new AppendRequest(eml, customFlag, currentFolder, null), false);
if (n.Tags.Count > 1)
{
IMessage[] oldMsgs = client.MailboxManager.GetMessagesByFolder(currentFolder);
client.RequestManager.SubmitAndWait(new MessageListRequest(currentFolder, null), false);
IMessage[] newMsgs = client.MailboxManager.GetMessagesByFolder(currentFolder);
IMessage newMsg = null;
foreach (IMessage imsg in newMsgs)
{
bool found = false;
foreach (IMessage omsg in oldMsgs)
{
if (imsg.UID == omsg.UID)
{
found = true;
break;
}
}
if (!found)
{
newMsg = client.MailboxManager.GetMessageByUID(imsg.UID, currentFolder.ID);
break;
}
}
// copy the email to all tag folders
for (int i = 1; i < n.Tags.Count; ++i)
{
if (cancelled)
{
break;
}
tagfolder = folder + "/" + n.Tags[i];
IFolder tagFolder = GetOrCreateFolderByPath(tagfolder);
client.RequestManager.SubmitAndWait(new CopyMessageRequest(newMsg, tagFolder, null), true);
client.RequestManager.SubmitAndWait(new MessageListRequest(tagFolder, null), true);
}
}
}
}
}