How do I send a gmail email in vb.net?

前端 未结 6 1637
情书的邮戳
情书的邮戳 2021-01-05 20:49

I want to send an email, but it gives me an error.

I have this code:

Sub sendMail(ByVal title As String, ByVal content As String)
    Dim SmtpServer          


        
6条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 21:40

    Try this - I know it works.

        Dim Mail As New MailMessage
        Dim SMTP As New SmtpClient("smtp.gmail.com")
    
        Mail.Subject = "Security Update"
        Mail.From = New MailAddress("name@gmail.com")
        SMTP.Credentials = New System.Net.NetworkCredential("name@gmail.com", "password") '<-- Password Here
    
        Mail.To.Add(address & "@gmail.com") 'I used ByVal here for address
    
        Mail.Body = "" 'Message Here
    
        SMTP.EnableSsl = True
        SMTP.Port = "587"
        SMTP.Send(Mail)
    

提交回复
热议问题