1

gmail id を使ってメールを送信したいのですが、コードは以下のとおりですが、エラーが発生しました。どうすればこれを解決できますか?

Imports System.Net
Imports System.Net.Mail

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("This will send a mail...")
        Try

            Dim smtpserver As New SmtpClient()
            Dim mail As New MailMessage()
            smtpserver.Credentials = New Net.NetworkCredential("myname@gmail.com", "password")
            smtpserver.Port = 465
            smtpserver.Host = "smtp.gmail.com"
            mail = New MailMessage()
            mail.From = New MailAddress("myname@gmail.com")
            mail.To.Add("to mail id")
            mail.Subject = "Test by bharat"
            mail.Body = "hello ooooooooooooooooooooooo"
            smtpserver.Send(mail)
            MsgBox("Mail Sent")
        Catch ex As Exception
            MsgBox(ex.ToString)
            Close()
        End Try


    End Sub
End Class
4

3 に答える 3

-1
Imports System.Net.Mail
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

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


        Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential("myemail@gmail.com", "Password")
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = True
            Smtp_Server.Host = "smtp.gmail.com"

            e_mail = New MailMessage()
            e_mail.From = New MailAddress(TextBox1.Text)
            e_mail.To.Add(TextBox2.Text)
            e_mail.Subject = "Email Sending"
            e_mail.IsBodyHtml = False
            e_mail.Body = txtmsg.Text
            Smtp_Server.Send(e_mail)
            MsgBox("Mail Sent")

        Catch error_t As Exception
            MsgBox(error_t.ToString)
        End Try

    End Sub

End Class
于 2013-09-27T20:44:26.350 に答える