Sending Email through Gmail

删除回忆录丶 提交于 2019-12-04 22:03:09

You just need to change port to 587

Try this code

    MailMessage mM = new MailMessage();
    mM.From = new MailAddress("from@gmail.com");
    mM.To.Add("to@gmail.com,to@yahoo.co.in");
    mM.Subject = subject;
    mM.Body = body;
    mM.IsBodyHtml = true;
    SmtpClient sC = new SmtpClient("smtp.gmail.com");
    sC.Port = 587;
    sC.Credentials = new NetworkCredential("from@gmail.com", "password");
    sC.EnableSsl = true;
    sC.Send(mM);
Sc.Credentials = new NetworkCredential("uid@gmail.com", "mypss");
Sc.Port = 587;

use this code to send mails using gmail account

Public Sub sendmail(ByVal story As String, ByVal from As String, ByVal Too As String)
    Dim mail As New System.Net.Mail.MailMessage()
    mail.[To].Add([too])
    mail.From = New MailAddress(from, "StoryPan", System.Text.Encoding.UTF8)
    mail.Subject = "Your Friend with ID: " + Session("userlogin").ToString() + "  Sending Story"
    mail.SubjectEncoding = System.Text.Encoding.UTF8
    mail.Body = "StoryPan:<br />" + story
    mail.BodyEncoding = System.Text.Encoding.UTF8
    mail.IsBodyHtml = True
    mail.Priority = MailPriority.High
    Dim client As New SmtpClient()
    client.Credentials = New System.Net.NetworkCredential(from, "panstory")
    client.Port = 587
    client.Host = "smtp.gmail.com"
    client.EnableSsl = True
    Try
        client.Send(mail)
        ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "HidePageAdd", "closeMainPopup()", True)
        lblposted.Visible = True
        lblposted.Text = "Email sent successfully."
    Catch ex As Exception
        lblemailerror.Visible = True
        lblemailerror.Text = "Send Email Failed"
    End Try
End Sub
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!