发送电子邮件从word文件中取出的信件的正文 [英] Send e-mail the body of the letter taken from the word file
本文介绍了发送电子邮件从word文件中取出的信件的正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天。我需要发一封信给电子邮件。但这封信的正文取自Word文件(.doc或.docx)
我知道如何执行简单的信件发送。
我尝试过:
Good day. I need to send a letter to the e-mail. But the body of the letter is taken from a Word file (.doc or .docx)
I know how to perform a simple letter sending.
What I have tried:
Imports System.Net.Mail
Imports System.Text
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim email As New MailMessage
Dim smtp As SmtpClient
smtp = New SmtpClient("smtp.yandex.ru")
smtp.Port = 587
smtp.Credentials = New Net.NetworkCredential("admin@yandex.ru", "")
email.From = New MailAddress("admin@yandex.ru")
email.To.Add(New MailAddress("SEVlasova@yandex.ru"))
email.Body = "Post" ' body of the letter take the text (data from MS Word (doc or docx)
email.Subject = "Post"
email.Attachments.Add(New System.Net.Mail.Attachment("D:\files.txt"))
smtp.Send(email)
End Sub<pre>
推荐答案
您可以通过以下方式打开MS Word文档来实现:
1)OpenXML:
- 使用C#for Visual Studio 2010中的Open XML(CSOpenXmlGetPlainText)示例 Office获取Word文档的纯文本 [ ^ ]
2)互操作:
- 如何:以编程方式打开现有文档 - Visual Studio | Microsoft Docs [ ^ ]
- 如何:以编程方式搜索和替换文档中的文本 - Visual Studio | Microsoft Docs [ ^ ]
- 如何:以编程方式关闭文档 - Visual Studio | Microsoft Docs [ ^ ]
You can achieve that by opening MS Word document via:
1) OpenXML:
- Office Get Plain Text of a Word Document using Open XML (CSOpenXmlGetPlainText) sample in C# for Visual Studio 2010[^]
2) Interop:
- How to: Programmatically open existing documents - Visual Studio | Microsoft Docs[^]
- How to: Programmatically search for and replace text in Documents - Visual Studio | Microsoft Docs[^]
- How to: Programmatically close documents - Visual Studio | Microsoft Docs[^]
这篇关于发送电子邮件从word文件中取出的信件的正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文