Last active
February 14, 2021 15:17
-
-
Save aspose-com-gists/3837cf82825bad3a302f30f13a6b9c32 to your computer and use it in GitHub Desktop.
Send Word Document as Email using C#
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
// Set position to 0 | |
mhtmlStream.Position = 0; | |
// Create email message from MHTML | |
MailMessage message = MailMessage.Load(mhtmlStream, new MhtmlLoadOptions()); | |
// Set email fields | |
message.Subject = "Sending Invoice in Email"; | |
message.From = "sender@gmail.com"; | |
message.To = "recipient@gmail.com"; |
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
// Load a Word document from disk | |
Document wordDocument = new Document("Word.docx"); | |
// Save document as MHTML into memory stream | |
MemoryStream mhtmlStream = new MemoryStream(); | |
wordDocument.Save(mhtmlStream, SaveFormat.Mhtml); |
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
// Send email via SMTP | |
SmtpClient client = new SmtpClient("smtp.gmail.com", 587, "sender@gmail.com", "pwd"); | |
client.SecurityOptions = SecurityOptions.SSLExplicit; | |
client.Send(message); |
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
// Load a Word document from disk | |
Document wordDocument = new Document("Word.docx"); | |
// Save document as MHTML into memory stream | |
MemoryStream mhtmlStream = new MemoryStream(); | |
wordDocument.Save(mhtmlStream, SaveFormat.Mhtml); | |
// Set position to 0 | |
mhtmlStream.Position = 0; | |
// Create email message from MHTML | |
MailMessage message = MailMessage.Load(mhtmlStream, new MhtmlLoadOptions()); | |
// Set email fields | |
message.Subject = "Sending Invoice in Email"; | |
message.From = "sender@gmail.com"; | |
message.To = "recipient@gmail.com"; | |
// Send email via SMTP | |
SmtpClient client = new SmtpClient("smtp.gmail.com", 587, "sender@gmail.com", "pwd"); | |
client.SecurityOptions = SecurityOptions.SSLExplicit; | |
client.Send(message); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment