【问题标题】:Visual basic web form. When I hit submit nothing happens.No email is sent. How do I tell what went wrong?Visual Basic Web 表单。当我点击提交时,没有任何反应。没有发送电子邮件。我怎么知道出了什么问题?
【发布时间】:2017-10-26 12:34:09
【问题描述】:

我正在使用 Visual Studio 2017

  • 仔细检查凭据
  • 尝试使用来自here 的 print.debug
  • 尝试打印到另一个文件,如 this 说要做 不知道如何找出代码不起作用的原因。

    <%@ Page Language="VB" aspcompat=true Debug="true" %>
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div><p>From:&nbsp;<asp:TextBox ID="txtFromAdress" runat="server" Columns="35"></asp:TextBox></p>
                <p>Subject:&nbsp;<asp:TextBox ID="txtSubject" runat="server" Columns="50"></asp:TextBox></p>
                <p>Message:&nbsp;<asp:TextBox ID="txtBody" runat="server" Columns="76" TextMode="multiLine" Rows="6"></asp:TextBox></p>
            <p><asp:Button ID="btnSend" runat="server" Text="Send Mail" /></p> 
            </div>
        </form>
    Debug.print txtFromAdress
    Debug.print txtSubject
    Debug.print txtBody
    </body>
    </html>
    

下面是代码:

<%@ Page Language="VB" aspcompat=true Debug="true" %>

Imports System.Net.Mail

Public Class WebForm1

    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
        Dim mail As New MailMessage()
        mail.From = New MailAddress(txtFromAdress.Text.Trim)
        mail.To.Add("email@domain.com")
        mail.Subject = txtSubject.Text.Trim()
        mail.Body = txtBody.Text.Trim()
        Debug.print mail
        Dim SmtpClient As New SmtpClient("smtp.office365.com")
        SmtpClient.UseDefaultCredentials = False
        SmtpClient.EnableSsl = True
        SmtpClient.Port = 587
        SmtpClient.Credentials = New Net.NetworkCredential("email@domain.com", "pword")
        n = FreeFile()
Open "root/test.txt" For Output As #n
Print #n, mail
        Try
            SmtpClient.Send(mail)
        Catch ex As Exception
            MsgBox(Err.Number & vbNewLine & ex.Message)
        End Try

【问题讨论】:

  • 去掉 aspcompat=true 再试一次
  • 这样做了,但仍然没有发生任何事情。

标签: vb.net forms email visual-studio-debugging


【解决方案1】:

打开命令提示符并运行以下命令:

telnet smtp.office365.com 587

反应是什么?如果它产生所需的结果,则下载 Wireshark 之类的工具,以便您可以分析请求和响应。

【讨论】:

  • 'telnet' 不是内部或外部命令、可运行程序或批处理文件。
  • 确保按照以下说明安装 Telnet:kb.ctera.com/article/…。安装后让我知道结果。
  • 我和我的 IT 部门谈过了。他们说它应该按原样工作,并建议我尝试用 c# 来代替。所以我放弃了这个尝试。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2014-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-31
  • 1970-01-01
  • 2015-03-15
  • 1970-01-01
相关资源
最近更新 更多