开发者

send email using gmail smtp c# [duplicate]

开发者 https://www.devze.com 2023-03-02 23:48 出处:网络
This question already has answers here: 开发者_JS百科Closed 11 years ago. Possible Duplicate: Sending email in .NET through Gmail
This question already has answers here: 开发者_JS百科 Closed 11 years ago.

Possible Duplicate:

Sending email in .NET through Gmail

hello,

Im using code like below but I get an error:

"Unable to connect to the remote server"

 MailMessage mail = new MailMessage();
        mail.To.Add("test1@gmail.com");
        mail.From = new MailAddress("test2@gmail.com");
        mail.Subject = "Test Email";
        string Body = "<b>Welcome to CodeDigest.Com!!</b>";
        mail.Body = Body;
        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.Credentials = new System.Net.NetworkCredential("test1@gmail.com", "myPass");
        smtp.EnableSsl = true;
        smtp.Send(mail);


You're not sending from the same email address you're authenticating with... You must add test1@gmail.com as the "from"

EDIT:As Bala R suggested, probably your firewall based on the error you get

0

精彩评论

暂无评论...
验证码 换一张
取 消