asp.net vb - docx corrupotion对电子邮件的接收

时间:2012-02-12 10:36:49

标签: asp.net vb.net

我尝试通过此表单发送Docx文件,电子邮件发送正常。 但docx文件恢复损坏.. 这是我的backgroudn代码:

'为与电子邮件相关的类添加命名空间 进口System.Net.Mail

部分类SendAttachment     继承System.Web.UI.Page

Protected Sub SendEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendEmail.Click
    'Make sure a file has been uploaded
    If String.IsNullOrEmpty(AttachmentFile.FileName) OrElse AttachmentFile.PostedFile Is Nothing Then
        Throw New ApplicationException("Egad, a file wasn't uploaded... you should probably use more graceful error handling than this, though...")
    End If

    ' UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
    Const ToAddress As String = "pelleg@shakuff.co.il"

    '(1) Create the MailMessage instance
    Dim mm As New MailMessage(UsersEmail.Text, ToAddress)

    '(2) Assign the MailMessage's properties
    mm.Subject = "שלוחת קורות חיים"
    mm.Body = Body.Text
    mm.IsBodyHtml = False

    'Attach the file
    mm.Attachments.Add(New Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName))

    '(3) Create the SmtpClient object
    Dim smtp As New SmtpClient

    '(4) Send the MailMessage (will use the Web.config settings)
    smtp.Send(mm)


    'Show the EmailSentForm Panel and hide the EmailForm Panel
    EmailSentForm.Visible = True
    EmailForm.Visible = False
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        'On the first page load, hide the EmailSentForm Panel
        EmailSentForm.Visible = False
    End If
End Sub

结束班

它的sendemail.aspx.vb文件。 有什么建议吗?

1 个答案:

答案 0 :(得分:1)

完全脱离了我的头脑,但尝试设置:

AttachmentFile.PostedFile.InputStream.Position = 0  
在你打电话之前

'Attach the file     mm.Attachments.Add(New Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName))