电子邮件发送两次

时间:2012-02-16 12:02:05

标签: asp.net vb.net

出于某种原因,每当我通过我的表单发送电子邮件时,它都会向我发送带有附件的电子邮件。但是在重新发送的电子邮件中,attachmant根本不起作用(filesize:0)。

我认为我的aspx.vb代码中有一些东西。

'Add the namespace for the email-related classes
Imports System.Net.Mail

Partial Class SendAttachment
    Inherits System.Web.UI.Page
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        'Make sure a file has been uploaded
        If AttachmentFile.PostedFile.ContentLength > 100000 Then
            'display error file size should be less than 100kb
        End If
        '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
        Const ToAddress As String = "pelleg@shakuff.co.il"
        Dim textMsg as String
        textMsg = "התנסת בפועל בעבודת ניהול ביצוע בתשתיות בינעירוניות בקנה מידה גדול" & (vbCrLf)  & q1.text & (vbCrLf) & (vbCrLf) & "רמת ההכרות שלך עם גורמים סטאטוריים, ממשלתיים והרשויות" & (vbCrLf) & q2.text & (vbCrLf) & (vbCrLf) & "הניסיון שלך בניהול פרויקט ביצוע בתחום התשתיות הבינעירוניות" & (vbCrLf) &q3.text & (vbCrLf) & (vbCrLf) & "ממליצים" & (vbCrLf) & c1.text & (Space(5)) & c2.text & (Space(5)) & c3.text & (vbCrLf) & (vbCrLf) & "מעוניין בהצעות נוספות" & (vbCrLf) & q4.text & (vbCrLf) & (vbCrLf) & "הניסיון שלך בתחום תשתיות הכבישים ועבודה מול מעצ " & (vbCrLf) & q5.text & (vbCrLf) & (vbCrLf) & "פרטים אישיים" & (vbCrLf) & (vbCrLf) & "שם מלא" & (vbCrLf) & pi1.text & (vbCrLf) & (vbCrLf) & "כתובת מייל" & (vbCrLf) & UsersEmail.Text & (vbCrLf) & (vbCrLf) & "טלפון" & (vbCrLf) & pi2.text & (vbCrLf) & (vbCrLf) &"שעות נוחות" & (vbCrLf) & pi3.text & (vbCrLf) & (vbCrLf) & (vbCrLf) & "הערות" & (vbCrLf) & body.text
 '
        '(1) Create the MailMessage instance
        Dim mm As New MailMessage(UsersEmail.Text, ToAddress)

        '(2) Assign the MailMessage's properties
        mm.Subject = pi1.text &  "-" & "JB-16"
        mm.Body = textMsg

        mm.IsBodyHtml = false

        'Attach the file
        mm.Attachments.Add(New Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName))
        mm.Attachments.Add(New Attachment(AttachmentFile2.PostedFile.InputStream, AttachmentFile2.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
End Class

任何想法?

2 个答案:

答案 0 :(得分:1)

确保您的.aspx页面中没有AutoWireUpEvent = true。

答案 1 :(得分:0)

您是否分配了两次点击处理程序?我看到你在函数定义中有“Handles btnSubmit.Click”。您是否正在为其他人分配onClick事件以使用该功能?

这是按钮点击事件两次触发的最常见原因。