1

试图获得一个非常基本的程序来向我发送电子邮件。我有 3 个文本框。

TextBox1 是一个只读文本框,其中包含我的电子邮件 TextBox2 用于“您的电子邮件” TextBox3 用于您的消息

还有一个按钮(Button1),上面写着“发送”

这是我整个项目的代码。为了安全起见,我在这个问题中删除了我的电子邮件和密码。

当我运行程序并在 TextBox2 中输入“Test1234@live.com”并在 TextBox3 中输入“TestEmail1234”并按发送时,它会将我带回编码页面并显示“SmtpException 未处理。发送邮件失败”

Imports System.Net.Mail

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim smtpServer As New SmtpClient()
        Dim mail As New MailMessage()

        smtpServer.Credentials = New Net.NetworkCredential("myemail@gmail.com", "mypassword")
        'using Gmail
        smtpServer.Port = 587
        smtpServer.Host = "smtp.gmail.com"
        smtpServer.EnableSsl = True

        mail = New MailMessage()
        mail.From = New MailAddress("my email@gmail.com", TextBox1.Text)
        mail.To.Add(TextBox1.Text)
        mail.Subject = TextBox2.Text
        mail.Body = TextBox3.Text

        smtpServer.Send(mail)

    End Sub
End Class
4

1 回答 1

1

有一些问题,我只是给你一个工作脚本

Imports System.Net.Mail
Public Class Form1
Dim message As New MailMessage
Dim smtp As New SmtpClient
Dim instance As IDisposable


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim Mail As New MailMessage
    Mail.Subject = "test email"
    Mail.To.Add("recieveradress@gmail.com")
    Mail.From = New MailAddress("senderadress@gmail.com")
    Mail.Body = "This is an email!"
    Dim SMTP As New SmtpClient("smtp.gmail.com")
    SMTP.EnableSsl = True
    SMTP.Credentials = New System.Net.NetworkCredential("senderaddress@gmail.com", "password")
    SMTP.Port = 587
    SMTP.Send(Mail)
    MsgBox("Sent Successfully")

End Sub
End Class
于 2012-12-06T00:10:13.400 回答