【问题标题】:asp.net vb - docx corrupotion on email recevingasp.net vb - 接收电子邮件时 docx 损坏
【发布时间】:2012-02-12 10:36:48
【问题描述】:

我正在尝试通过我制作的此表单发送 Docx 文件,电子邮件发送正常。 但是docx文件又损坏了.. 这是我的背景代码:

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

部分类发送附件 继承 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 文件。 有什么建议吗?

【问题讨论】:

    标签: asp.net vb.net


    【解决方案1】:

    完全不在我的脑海中,但尝试设置:

    AttachmentFile.PostedFile.InputStream.Position = 0  
    

    打电话之前:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-04
      • 2016-12-06
      • 2019-12-20
      • 1970-01-01
      • 2010-09-23
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      相关资源
      最近更新 更多