本文整理汇总了C#中MailMessage.Save方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.Save方法的具体用法?C# MailMessage.Save怎么用?C# MailMessage.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MailMessage
的用法示例。
在下文中一共展示了MailMessage.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
// ExStart:CreateNewMailMessage
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Email();
// Create a new instance of MailMessage class
MailMessage message = new MailMessage();
// Set subject of the message, Html body and sender information
message.Subject = "New message created by Aspose.Email for .NET";
message.HtmlBody = "<b>This line is in bold.</b> <br/> <br/>" + "<font color=blue>This line is in blue color</font>";
message.From = new MailAddress("[email protected]", "Sender Name", false);
// Add TO recipients and Add CC recipients
message.To.Add(new MailAddress("[email protected]", "Recipient 1", false));
message.To.Add(new MailAddress("[email protected]", "Recipient 2", false));
message.CC.Add(new MailAddress("[email protected]", "Recipient 3", false));
message.CC.Add(new MailAddress("[email protected]", "Recipient 4", false));
// Save message in EML, EMLX, MSG and MHTML formats
message.Save(dataDir + "Message_out.eml", SaveOptions.DefaultEml);
message.Save(dataDir + "Message_out.emlx", SaveOptions.CreateSaveOptions(MailMessageSaveType.EmlxFormat));
message.Save(dataDir + "Message_out.msg", SaveOptions.DefaultMsgUnicode);
message.Save(dataDir + "Message_out.mhtml", SaveOptions.DefaultMhtml);
// ExEnd:CreateNewMailMessage
}
示例2: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Email();
string dstEmail = dataDir + "test.eml";
// Create a new instance of MailMessage class
MailMessage message = new MailMessage();
// Set subject of the message
message.Subject = "New message created by Aspose.Email for .NET";
// Set Html body
message.IsBodyHtml = true;
message.HtmlBody = "<b>This line is in bold.</b> <br/> <br/><font color=blue>This line is in blue color</font>";
// Set sender information
message.From = "[email protected]";
// Add TO recipients
message.To.Add("[email protected]");
message.To.Add("[email protected]");
//Add CC recipients
message.CC.Add("[email protected]");
message.CC.Add("[email protected]");
// Save message in EML, MSG and MHTML formats
message.Save(dataDir + "Message.eml", Aspose.Email.Mail.SaveOptions.DefaultEml);
message.Save(dataDir + "Message.msg", Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode);
message.Save(dataDir + "Message.mhtml", Aspose.Email.Mail.SaveOptions.DefaultMhtml);
Console.WriteLine(Environment.NewLine + "Created new email in EML, MSG and MHTML formats successfully.");
}
示例3: Main
static void Main(string[] args)
{
// Create an instance of type MailMessage
MailMessage msg = new MailMessage();
// Set properties of message like subject, to and HTML body
// Set subject
msg.Subject = "This MSG file is created using Aspose.Email for .NET";
// Set from (sender) address
msg.Sender = new MailAddress("[email protected]", "From Name");
// Set to (recipient) address and name
msg.To.Add(new MailAddress("[email protected]", "To Name"));
// Set HTML body of the email message
msg.HtmlBody = @"<html><p>This MSG file is created using C# code.</p>" +
"<p>Microsoft Outlook does not need to be installed on the machine running this code.</p>" +
"<p>This method is suitable for creating MSG files on the server side.</html>";
// Add attachments to the message file
msg.Attachments.Add(new Attachment("image.bmp"));
msg.Attachments.Add(new Attachment("pic.jpeg"));
// Save as Outlook MSG file
string strSaveFile = "TestAspose.msg";
msg.Save(strSaveFile, MessageFormat.Msg);
}
示例4: Run
public static void Run()
{
// ExStart:EmbeddedObjects
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Email();
string dstEmail = dataDir + "EmbeddedImage.msg";
// Create an instance of the MailMessage class and Set the addresses and Set the content
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "This is an email";
// Create the plain text part It is viewable by those clients that don't support HTML
AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content", null, "text/plain");
/* Create the HTML part.To embed images, we need to use the prefix 'cid' in the img src value.
The cid value will map to the Content-Id of a Linked resource. Thus <img src='cid:barcode'> will map to a LinkedResource with a ContentId of //'barcode'. */
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:barcode>", null, "text/html");
// Create the LinkedResource (embedded image) and Add the LinkedResource to the appropriate view
LinkedResource barcode = new LinkedResource(dataDir + "1.jpg", MediaTypeNames.Image.Jpeg)
{
ContentId = "barcode"
};
mail.LinkedResources.Add(barcode);
mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);
mail.Save(dataDir + "EmbeddedImage_out.msg", SaveOptions.DefaultMsgUnicode);
// ExEnd:EmbeddedObjects
Console.WriteLine(Environment.NewLine + "Message saved with embedded objects successfully at " + dstEmail);
}
示例5: Main
static void Main(string[] args)
{
string FilePath = @"E:\Aspose\Aspose VS VSTO\Sample Files\ExportEmail.msg";
//Create an instance of the MailMessage class
MailMessage msg = new MailMessage();
//Export to MHT format
msg.Save(FilePath, SaveOptions.DefaultMsg);
}
示例6: Run
public static void Run()
{
// ExStart:CreatEMLFileAndConvertToMSG
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Outlook();
// Create new message and save as EML
MailMessage message = new MailMessage("[email protected]", "[email protected]");
message.Subject = "subject of email";
message.HtmlBody = "<b>Eml to msg conversion using Aspose.Email</b>" +
"<br><hr><br><font color=blue>This is a test eml file which will be converted to msg format.</font>";
// Add attachments
message.Attachments.Add(new Attachment(dataDir + "attachment_1.doc"));
message.Attachments.Add(new Attachment(dataDir + "download.png"));
// Save it EML
message.Save(dataDir + "CreatEMLFileAndConvertToMSG_out.eml", SaveOptions.DefaultEml);
// Save it to MSG
message.Save(dataDir + "CreatEMLFileAndConvertToMSG_out.msg", SaveOptions.DefaultMsgUnicode);
// ExEnd:CreatEMLFileAndConvertToMSG
}
示例7: Run
public static void Run()
{
// ExStart:SetDefaultTextEncoding
// Create an instance of MailMessage
string fileName = RunExamples.GetDataDir_Email();
MailMessage msg = new MailMessage();
// Set the default or preferred encoding. This encoding will be used as the default for the from/to email addresses, subject and body of message.
msg.PreferredTextEncoding = Encoding.GetEncoding(28591);
// Set email addresses, subject and body
msg.From = new MailAddress("[email protected]", "démo");
msg.To.Add(new MailAddress("[email protected]", "démo"));
msg.Subject = "démo";
msg.HtmlBody = "démo";
msg.Save(fileName + "SetDefaultTextEncoding_out.msg", SaveOptions.DefaultMsg);
// ExEnd:SetDefaultTextEncoding
}
示例8: Run
static void Run()
{
// ExStart: SaveMessageAsOFT
/// <summary>
/// This exmpale shows how to save an email as Outlook Template (.OFT) file using the MailMesasge API
/// MsgSaveOptions.SaveAsTemplate - Set to true, if need to be saved as Outlook File Template(OFT format).
/// Available from Aspose.Email for .NET 6.4.0 onwards
/// </summary>
using (MailMessage eml = new MailMessage("[email protected]", "[email protected]", "template subject", "Template body"))
{
string oftEmlFileName = "EmlAsOft.oft";
MsgSaveOptions options = SaveOptions.DefaultMsgUnicode;
options.SaveAsTemplate = true;
eml.Save(oftEmlFileName, options);
}
// ExEnd: SaveMessageAsOFT
}
示例9: Run
public static void Run()
{
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_SMTP();
string dstEmail = dataDir + "MsgHeaders.msg";
// Create an instance MailMessage class
MailMessage msg = new MailMessage();
// Specify ReplyTo
msg.ReplyToList.Add("[email protected]");
// From field
msg.From = "[email protected]";
// To field
msg.To.Add("[email protected]");
// Adding Cc and Bcc Addresses
msg.CC.Add("[email protected]");
msg.Bcc.Add("[email protected]");
// Message subject
msg.Subject = "test mail";
// Specify Date
msg.Date = new DateTime(2006, 3, 6);
// Specify XMailer
msg.XMailer = "Aspose.Email";
// Specify Secret Header
msg.Headers.Add("secret-header", "mystery");
// Save message to disc
msg.Save(dstEmail, SaveOptions.DefaultMsgUnicode);
Console.WriteLine(Environment.NewLine + "Message saved with customized headers successfully at " + dstEmail);
}
示例10: Run
public static void Run()
{
// ExStart:ManagingEmailAttachments
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Email();
// Create an instance of MailMessage class
MailMessage message = new MailMessage {From = "[email protected]"};
message.To.Add("[email protected]");
// Load an attachment
Attachment attachment = new Attachment(dataDir + "1.txt");
// Add Multiple Attachment in instance of MailMessage class and Save message to disk
message.Attachments.Add(attachment);
message.AddAttachment(new Attachment(dataDir + "1.jpg"));
message.AddAttachment(new Attachment(dataDir + "1.doc"));
message.AddAttachment(new Attachment(dataDir + "1.rar"));
message.AddAttachment(new Attachment(dataDir + "1.pdf"));
message.Save(dataDir + "outputAttachments_out.msg", SaveOptions.DefaultMsgUnicode);
// ExEnd:ManagingEmailAttachments
}
示例11: Main
static void Main(string[] args)
{
// Create an instance of the Aspose.Email.MailMessage class
MailMessage msg = new MailMessage();
// Set recipients information
msg.To = "[email protected]";
msg.CC = "[email protected]";
// Set the subject
msg.Subject = "Subject";
// Set HTML body
msg.HtmlBody = "<h3>HTML Heading 3</h3> <u>This is underlined text</u>";
// Add an attachment
msg.Attachments.Add(new Attachment("image.bmp"));
// Save it in local disk
string strMsg = "TestAspose.msg";
msg.Save(strMsg, MessageFormat.Msg);
}
示例12: Run
public static void Run()
{
// ExStart:SetEmailHeaders
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Email();
// Create an instance MailMessage class
MailMessage mailMessage = new MailMessage();
// Specify ReplyTo, From, To field, Cc and Bcc Addresses
mailMessage.ReplyToList.Add("[email protected]");
mailMessage.From = "[email protected]";
mailMessage.To.Add("[email protected]");
mailMessage.CC.Add("[email protected]");
mailMessage.Bcc.Add("[email protected]");
// Specify Date, Message subject, XMailer, Secret Header, Save message to disc
mailMessage.Subject = "test mail";
mailMessage.Date = new System.DateTime(2006, 3, 6);
mailMessage.XMailer = "Aspose.Email";
mailMessage.Headers.Add("secret-header", "mystery");
mailMessage.Save(dataDir + "MessageHeaders_out.msg", SaveOptions.DefaultMsg);
// ExEnd:SetEmailHeaders
}
示例13: Run
public static void Run()
{
// ExStart:RemoveAttachments
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_Email();
string dstEmailRemoved = dataDir + "RemoveAttachments.msg";
// Create an instance of MailMessage class
MailMessage message = new MailMessage();
message.From = "[email protected]";
message.To.Add("[email protected]");
// Load an attachment
Attachment attachment = new Attachment(dataDir + "1.txt");
// Add Multiple Attachment in instance of MailMessage class and Save message to disk
message.Attachments.Add(attachment);
message.AddAttachment(new Attachment(dataDir + "1.jpg"));
message.AddAttachment(new Attachment(dataDir + "1.doc"));
message.AddAttachment(new Attachment(dataDir + "1.rar"));
message.AddAttachment(new Attachment(dataDir + "1.pdf"));
// Remove attachment from your MailMessage and Save message to disk after removing a single attachment
message.Attachments.Remove(attachment);
message.Save(dstEmailRemoved, SaveOptions.DefaultMsgUnicode);
// Create a loop to display the no. of attachments present in email message
foreach (Attachment getAttachment in message.Attachments)
{
// Save your attachments here and Display the the attachment file name
getAttachment.Save(dataDir + "/RemoveAttachments/" + "attachment_out" + getAttachment.Name);
Console.WriteLine(getAttachment.Name);
}
// ExEnd:RemoveAttachments
Console.WriteLine(Environment.NewLine + "Attachments removed successfully from " + dstEmailRemoved);
}
示例14: InvioMessaggio
//.........这里部分代码省略.........
if (motivoMessaggio != MotivoMessaggio.ScadenzaContratto && motivoMessaggio != MotivoMessaggio.NotificaResponsabileAttivita)
{
try
{
mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure;
string destinatarioRicevuta;
switch (impostazioniAzienda.ControlloRapportinoMessaggistica)
{
case ControlloRapportino.Mittente:
destinatarioRicevuta = mittente;
break;
case ControlloRapportino.Automatico:
destinatarioRicevuta = "[email protected]";
break;
case ControlloRapportino.IndirizzoSpecifico:
destinatarioRicevuta = impostazioniAzienda.EmailControlloRapportinoMessaggistica;
break;
default:
destinatarioRicevuta = mittente;
break;
}
mailMessage.Headers.Add("Return-Receipt-To", destinatarioRicevuta);
mailMessage.Headers.Add("Disposition-Notification-To", destinatarioRicevuta);
mailMessage.Headers.Add("X-Confirm-Reading-To", destinatarioRicevuta);
// ========================================================
// Salvare il messaggio in formato .eml
// ========================================================
var emailStream = new MemoryStream();
mailMessage.MessageId = referenceId;
mailMessage.Save(emailStream, MessageFormat.Eml);
messaggio.Body = emailStream.ToArray();
messaggio.FileName = $"Email_{DateTime.Now.ToString("dd-mm-yyyy")}.eml";
messaggio.FileExtension = ".eml";
// Aggiungo la mail generata alla lista degli allegati
// ----------------------------------------------------
var documentMessage = _documentService.SaveDocument(messaggio.Body, messaggio.FileName, messaggio.FileExtension, null, idAzienda);
if (documentMessage.Documento != null)
{
fullPathFile = documentMessage.FilePath;
var checksum = documentMessage.Documento.Checksum;
messaggio.FileId = checksum;
if (allegati == null)
allegati = new List<DocumentInfo>();
allegati.Add(messaggio);
}
}
catch (Exception ex)
{
invioRiuscito = false;
message = "Si sono verificati problemi nel salvataggio del file EML :" + Environment.NewLine + ex.Message;
_log.FatalFormat("Errore inaspettato durante il salvataggio del file eml - {0} - oggetto:{1} - destinatario:{2}", ex, Utility.GetMethodDescription(), oggetto, destinatari.Aggregate("<NESSUNO>", (current, dest) => current + (dest + ", ")));
}
}
}
}
}
else
invioRiuscito = false;
}
// ========================================================
示例15: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_SMTP();
string dstEmail = dataDir + "outputAttachments.msg";
string dstEmailRemoved = dataDir + "outputAttachmentRemoved.msg";
//Create an instance of MailMessage class
MailMessage message = new MailMessage();
//From
message.From = "[email protected]";
//to whom
message.To.Add("[email protected]");
// 1.
// Attaching an Attachment to an Email
//Adding 1st attachment
//Create an instance of Attachment class
Attachment attachment;
//Load an attachment
attachment = new Attachment(dataDir + "1.txt");
//Add attachment in instance of MailMessage class
message.Attachments.Add(attachment);
//Add 2nd Attachment
message.AddAttachment(new Attachment(dataDir + "1.jpg"));
//Add 3rd Attachment
message.AddAttachment(new Attachment(dataDir + "1.doc"));
//Add 4th Attachment
message.AddAttachment(new Attachment(dataDir + "1.rar"));
//Add 5th Attachment
message.AddAttachment(new Attachment(dataDir + "1.pdf"));
//Save message to disk
message.Save(dstEmail, Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode);
// 2.
// Removing an Attachment
//Remove attachment from your MailMessage
message.Attachments.Remove(attachment);
//Save message to disk after removing a single attachment
message.Save(dstEmailRemoved, Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode);
// 3.
// Display remaining attachment names from message and save attachments
//Create a loop to display the no. of attachments present in email message
foreach (Attachment atchmnt in message.Attachments)
{
//Save your attachments here
atchmnt.Save(dataDir + "attachment_" + atchmnt.Name);
//display the the attachment file name
Console.WriteLine(atchmnt.Name);
}
Console.WriteLine(Environment.NewLine + "Attachments removed successfully from " + dstEmailRemoved);
}