Last active
January 18, 2022 06:40
-
-
Save aspose-com-gists/7126ba23a3ba099642e13dbfbfd94970 to your computer and use it in GitHub Desktop.
Aspose.Email - Create and Send Emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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("from@domain.com", "Sender Name", false); | |
// Add To recipients and CC recipients | |
message.To.Add(new MailAddress("to1@domain.com", "Recipient 1", false)); | |
message.CC.Add(new MailAddress("cc1@domain.com", "Recipient 3", false)); | |
// Save message in EML/EMLX/MSG/MHTML format | |
message.Save("EmailMessage.eml", SaveOptions.DefaultEml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Set subject of the message, Html body, sender, and receiver 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("from@domain.com", "Sender Name", false); | |
message.To.Add(new MailAddress("to1@domain.com", "Recipient 1", false)); | |
// Specify encoding | |
message.BodyEncoding = Encoding.ASCII; | |
// Save message in EML/EMLX/MSG/MHTML format | |
message.Save("EmailMessage.msg", SaveOptions.DefaultMsgUnicode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Set subject of the message, body and sender information | |
message.Subject = "New message created by Aspose.Email for .NET"; | |
message.Body = "This is the body of the email."; | |
message.From = new MailAddress("from@domain.com", "Sender Name", false); | |
// Add To recipients and CC recipients | |
message.To.Add(new MailAddress("to1@domain.com", "Recipient 1", false)); | |
message.CC.Add(new MailAddress("cc1@domain.com", "Recipient 3", false)); | |
// Add attachments | |
message.Attachments.Add(new Attachment("word.docx")); | |
// Save message in EML, EMLX, MSG and MHTML formats | |
message.Save("EmailMessage.eml", SaveOptions.DefaultEml); | |
message.Save("EmailMessage.emlx", SaveOptions.CreateSaveOptions(MailMessageSaveType.EmlxFormat)); | |
message.Save("EmailMessage.msg", SaveOptions.DefaultMsgUnicode); | |
message.Save("EmailMessage.mhtml", SaveOptions.DefaultMhtml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create SmtpClient and specify server, port, user name and password | |
SmtpClient client = new SmtpClient("mail.server.com", 25, "Username", "Password"); | |
// Create instances of MailMessage class and specify To, From, Subject and Message | |
MailMessage message1 = new MailMessage("msg1@from.com", "msg1@to.com", "Subject1", "message1, how are you?"); | |
MailMessage message2 = new MailMessage("msg1@from.com", "msg2@to.com", "Subject2", "message2, how are you?"); | |
MailMessage message3 = new MailMessage("msg1@from.com", "msg3@to.com", "Subject3", "message3, how are you?"); | |
// Create an instance of MailMessageCollection and add email messages to it | |
MailMessageCollection manyMsg = new MailMessageCollection(); | |
manyMsg.Add(message1); | |
manyMsg.Add(message2); | |
manyMsg.Add(message3); | |
try | |
{ | |
// Send messages | |
client.Send(manyMsg); | |
} | |
catch (Exception ex) | |
{ | |
Trace.WriteLine(ex.ToString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create MailMessage instance. You can create a new message or load a already created message file (eml, msg, etc.) | |
MailMessage msg = MailMessage.Load("EmailMessage.msg"); | |
// Create an instance of SmtpClient class | |
SmtpClient client = new SmtpClient(); | |
// Specify your mailing Host, Username, Password, Port # and Security option | |
client.Host = "mail.server.com"; | |
client.Username = "username"; | |
client.Password = "password"; | |
client.Port = 587; | |
client.SecurityOptions = SecurityOptions.SSLExplicit; | |
// Specify your mailing Host, Username, Password, Port # and Security option | |
client.Host = "mail.server.com"; | |
client.Username = "username"; | |
client.Password = "password"; | |
client.Port = 587; | |
client.SecurityOptions = SecurityOptions.SSLExplicit; | |
// Send messages | |
client.SendAsync(msg); | |
Console.WriteLine("Sending message..."); | |
msg.Dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create MailMessage instance. You can create a new message or load a already created message file (eml, msg, etc.) | |
MailMessage msg = MailMessage.Load("EmailMessage.msg"); | |
// Create an instance of SmtpClient class | |
SmtpClient client = new SmtpClient(); | |
// Specify your mailing Host, Username, Password, Port # and Security option | |
client.Host = "mail.server.com"; | |
client.Username = "username"; | |
client.Password = "password"; | |
client.Port = 587; | |
client.SecurityOptions = SecurityOptions.SSLExplicit; | |
try | |
{ | |
// Send this email | |
client.Send(msg); | |
} | |
catch (Exception ex) | |
{ | |
Trace.WriteLine(ex.ToString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment