c# – 如何添加smtp hotmail帐户来发送邮件
发布时间:2020-12-15 20:47:24 所属栏目:百科 来源:网络整理
导读:我写了一些代码,以便发送电子邮件,但我只能从gmail帐户发送邮件到gmail帐户,我想使用hotmail帐户我该怎么办?谢谢 它是 SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");mail.From = new MailAddress("xxx@gmail.com");mail.To.Add("kalaylevent@
我写了一些代码,以便发送电子邮件,但我只能从gmail帐户发送邮件到gmail帐户,我想使用hotmail帐户我该怎么办?谢谢
它是 SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("xxx@gmail.com"); mail.To.Add("kalaylevent@gmail.com"); mail.Subject = "Test Mail - 1"; mail.IsBodyHtml = true; string htmlBody; htmlBody = "Write some HTML code here"; mail.Body = htmlBody; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("kalaylevent@gmail.com","mypassword"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); 解决方法
我更改了一些代码并测试成功(从Hotmail到Gmail)
SmtpClient SmtpServer = new SmtpClient("smtp.live.com"); var mail = new MailMessage(); mail.From = new MailAddress("youremail@hotmail.com"); mail.To.Add("to@gmail.com"); mail.Subject = "Test Mail - 1"; mail.IsBodyHtml = true; string htmlBody; htmlBody = "Write some HTML code here"; mail.Body = htmlBody; SmtpServer.Port = 587; SmtpServer.UseDefaultCredentials = false; SmtpServer.Credentials = new System.Net.NetworkCredential("youremail@hotmail.com","password"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |