办公室打开的XML文件无法打开,因为内容存在问题

时间:2016-01-31 23:37:27

标签: asp.net vb.net

我试图将msword文件作为附件发送而不将文档存储在硬盘上,但如果将文档指定为文本文件即记事本,则它可以正常工作。但是如果附件被指定为word文档,文档将被附加和发送,但它将打开并显示错误消息“办公室打开XML文件无法打开,因为内容存在问题”有人可以帮助我< / p>

Sub sendattachment(S as Object,E as EventArgs)
dim EmailMessage as string = "Dear "& firstname.text &"<br>, Please find  attached <br><br>Thank you"
Dim strFrom = "me<support@mymail.com>"
Dim strTo = username.text 
Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo))  
MailMsg.BodyEncoding = Encoding.Default  
MailMsg.Subject = " Subject"
MailMsg.Body = EmailMessage
MailMsg.Priority = MailPriority.High  
MailMsg.IsBodyHtml = True  
'Smtpclient to send the mail message  
Dim SmtpMail As New SmtpClient  
Dim basicAuthenticationInfo As New system.Net.NetworkCredential("me@theemail.com", "thepassword") 

'Get some binary data
Dim data As Byte() = GetData()
'save the data to a memory stream
Dim ms As New MemoryStream(data)
'create the attachment from a stream. Be sure to name the data with a file and file type

MailMsg.Attachments.Add(新附件(ms,“filename.docx”,“application / msword”))
    SmtpMail.Host =“mail.myemail.com”
    SmtpMail.UseDefaultCredentials = False
    SmtpMail.Credentials = basicAuthenticationInfo

SmtpMail.Send(MailMsg)  

end sub

Function GetData() As Byte()
Dim s As String = "this is some text"
Dim data As Byte() = Encoding.ASCII.GetBytes(s)
Return data
End Function 'GetData

0 个答案:

没有答案