简体   繁体   English

Vb.Net无法发送邮件

[英]Vb.Net Could not send the Mail

Im adding a function to my program, so the user can send Mails with reports while using it. 我在程序中添加了一个功能,因此用户可以在使用它的同时发送带有报告的邮件。 My problem is I get a error after I try to send the Mail " Mail could not be send" I unlocked smtp port from Gmail side, so I think my code has got something wrong but I cant find it. 我的问题是我尝试发送邮件后收到错误消息“无法发送邮件”,我从Gmail端解锁了smtp端口,所以我认为我的代码有问题,但我找不到它。 Thats my code 那就是我的代码

 Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    If TextBox18.Text.EndsWith("@gmail.com") Then
        Dim Mail As New MailMessage
        Mail.Subject = (TextBox17.Text)
        Mail.To.Add(TextBox16.Text)
        Mail.From = New MailAddress(TextBox18.Text)
        Mail.Body = (Betreff.Text)
        Dim SMTP As New SmtpClient("smpt.gmail.com")
        SMTP.EnableSsl = True
        SMTP.Credentials = New System.Net.NetworkCredential(TextBox18.Text, password.Text)
        SMTP.Port = "587"
        SMTP.Send(Mail)
    ElseIf TextBox18.Text.EndsWith("@buch-automation.de") Then
        Dim Mail As New MailMessage
        Mail.Subject = TextBox13.Text
        Mail.To.Add(TextBox16.Text)
        Mail.From = New MailAddress(TextBox18.Text)
        Mail.Body = Betreff.Text
        Dim SMTP As New SmtpClient("smtp.1und1.de")
        SMTP.EnableSsl = True
        SMTP.Credentials = New System.Net.NetworkCredential(TextBox18.Text, password.Text)
        SMTP.Port = "993"
        SMTP.Send(Mail)
    End If
End Sub

End Class 末级

Switch Option Strict On to start with (and always). 将Option Strict(严格启用)切换为(始终)开始。 Also smpt should be smtp Thanks Matt 另外smpt应该是smtp,谢谢Matt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM