织梦CMS - 轻松建站从此开始!

abg欧博官网|登陆|游戏|

How to Send Email via Yandex SMTP (C# ASP.NET)

时间:2025-08-27 13:37来源: 作者:admin 点击: 2 次
Formerly, I used my server as mail host and was sending emails via my own host. Now, I use Yandex as my mail server. I'm trying to send emails via Yan

Formerly, I used my server as mail host and was sending emails via my own host. Now, I use Yandex as my mail server. I'm trying to send emails via Yandex SMTP. However, I could not achieve it. I get "the operation has timed out" message every time. I'm able to send & receive email with the same settings when I use Thunderbird. Hence, there is no issue with the account. I appreciate your guidance. You can see my code below:

EmailCredentials credentials = new EmailCredentials(); credentials.Domain = "domain.com"; credentials.SMTPUser = "[email protected]"; credentials.SMTPPassword = "password"; int SmtpPort = 465; string SmtpServer = "smtp.yandex.com"; System.Net.Mail.MailAddress sender = new System.Net.Mail.MailAddress(senderMail, senderName, System.Text.Encoding.UTF8); System.Net.Mail.MailAddress recipient = new System.Net.Mail.MailAddress(recipientEmail, recipientName, System.Text.Encoding.UTF8); System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage(sender, recipient); email.BodyEncoding = System.Text.Encoding.UTF8; email.SubjectEncoding = System.Text.Encoding.UTF8; System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(mailBody, @"<(.|\n)*?>", string.Empty), null, MediaTypeNames.Text.Plain); System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mailBody, null, MediaTypeNames.Text.Html); email.AlternateViews.Clear(); email.AlternateViews.Add(plainView); email.AlternateViews.Add(htmlView); email.Subject = mailTitle; System.Net.Mail.SmtpClient SMTP = new System.Net.Mail.SmtpClient(); SMTP.Host = SmtpServer; SMTP.Port = SmtpPort; SMTP.EnableSsl = true; SMTP.Credentials = new System.Net.NetworkCredential(credentials.SMTPUser, credentials.SMTPPassword); SMTP.Send(email);

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-08-27 20:08 最后登录:2025-08-27 20:08
栏目列表
推荐内容