C# SMTP email sending code fails for Yahoo Mail but works fine for other servers, can anyone help?

后端 未结 5 2124
孤城傲影
孤城傲影 2020-12-16 23:26

I am using this code to send an SMTP email via the yahoo SMTP server, it is for a personal project I am writing.

using System.Net.Mail;
using System.Net;

Sm         


        
5条回答
  •  渐次进展
    2020-12-16 23:43

    using System.Net.Mail;
    using System.Net;
    
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    
        private void btn_Send_Click(object sender, RoutedEventArgs e)
        {
            MailMessage oMail = new MailMessage(new MailAddress("username@yahoo.com"), new MailAddress("username@yahoo.com"));
            SmtpClient oSmtp = new SmtpClient();
            oSmtp.Host = "smtp.mail.yahoo.com";
            oSmtp.Credentials = new NetworkCredential("username", "password");
            oSmtp.EnableSsl = false;
            oSmtp.Port = 587;
            oSmtp.Send(oMail);
        }
    }
    

提交回复
热议问题