在c#中发送电子邮件

时间:2012-06-25 09:20:05

标签: c# .net email smtp credentials

我想在c#中发送电子邮件。我实现所有代码但收到错误......... it  在smtp.port = 465上指出rror;我也使用代码来指定host.but我   不明白为什么我会收到这种类型的错误????????

.aspx代码

        public void click(object sender, EventArgs sd)
            {


                try
                {



                    System.Net.Mail.MailMessage message = new   
   System.Net.Mail.MailMessage();
                    //smessage.To.Add(TextBox1.Text);
                    message.To.Add(System.Net.Mail.MailAddress(TextBox1.Text));
                    message.Subject = "This is the Subject line";
                    message.From = new System.Net.Mail.MailAddress(TextBox2.Text);
                    message.Body = "This is the message body";
                    System.Net.Mail.SmtpClient smtp = new        
               System.Net.Mail.SmtpClient("yoursmtphost");
                    smtp.Host = "smtp.yahoo.mail.com";
                    smtp.Port = 465;

                    smtp.Send(message);
                }
                catch (Exception gf)
                {

                }
            }

1 个答案:

答案 0 :(得分:1)

您尚未向服务器提供任何凭据。雅虎如何知道你是谁?

此外,您已在构造函数中定义了主机(不是错误的原因,但只是想我会指出它)System.Net.Mail.SmtpClient("yoursmtphost");然后将其重新定义为smtp.yahoo.mail.com

有一篇文章可以帮助您通过C#连接到Yahoo Mail:

http://www.emailarchitect.net/easendmail/kb/csharp.aspx?cat=3