gpt4 book ai didi

asp.net - System.Net.Mail 新的 MailMessage 随机发送重复的电子邮件?

转载 作者:行者123 更新时间:2023-12-02 14:32:07 25 4
gpt4 key购买 nike

我正在使用下面的代码来生成电子邮件。由于某种原因,它会随机发送重复的电子邮件。这种情况不会一直发生,每个月只会发生几次。您在我的代码中看到任何可能导致此问题的内容吗?当用户单击页面上的提交按钮时会触发它。我可以添加一些东西来防止这种情况发生吗? TIA

Try
Dim Attachment As String
Attachment = path + myUniqueFileName

Dim mailMessage As MailMessage = New MailMessage
mailMessage.From = New MailAddress("Test@Test.com")
mailMessage.Subject = "Report " + " " + myUniqueFileName
mailMessage.IsBodyHtml = True
mailMessage.To.Add(New MailAddress(Session("EmailAddress")))
mailMessage.Attachments.Add(New Attachment(Attachment))
mailMessage.Body = "Attached is your report"

Dim smtp As SmtpClient = New SmtpClient

smtp.Host = "mail.net"

Dim NetworkCred As System.Net.NetworkCredential = New System.Net.NetworkCredential

smtp.Credentials = New NetworkCredential("test", "test")
smtp.UseDefaultCredentials = False
smtp.Send(mailMessage)

Catch ex As Exception

Dim message As String = ex.ToString
Dim sb As New System.Text.StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("window.onload=function(){")
sb.Append("alert('")
sb.Append(message)
sb.Append("\n")
sb.Append(String.Format("{0:f2}", Convert.ToDouble(TotalAmount)))
sb.Append("')};")
sb.Append("</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", sb.ToString())

End Try

图像按钮代码:

 <asp:ImageButton ID="cmdFinish" runat="server" Height="38px" ImageUrl="~/Images/Finish.png" Width="99px" UseSubmitBehavior="false" OnClientClick="this.disabled = true; this.value = 'Sending...';" Text="Send" />

最佳答案

我以前遇到过同样的问题,所以我想我可以分享我的解决方案:

这是我的按钮标记代码,以避免再次重新单击它:

<asp:Button ID="btnSend" runat="server" CssClass="btn btn-primary" Width="150px" UseSubmitBehavior="false" OnClientClick="this.disabled = true; this.value = 'Sending...';" Text="Send" />

注意OnClientClick="this.disabled = true; this.value = '正在发送...'

单击按钮后,它将禁用您的按钮并更改其文本。

另外,为了避免刷新页面时重新保存/重新提交/重新发送数据,我刚刚记忆了我的表单:

Response.Redirect("~/yourForm.aspx")

关于asp.net - System.Net.Mail 新的 MailMessage 随机发送重复的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38123954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com