code发送电子邮件 [英] code to send email

查看:203
本文介绍了code发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么错在这里?

What am I doing wrong here?

 private void SendMail(string from, string body)
    {
        string mailServerName = "plus.pop.mail.yahoo.com";
        MailMessage message = new MailMessage(from, "aditya15417@yahoo.com", "feedback", body);
        SmtpClient mailClient = new SmtpClient();
        mailClient.Host = mailServerName;
        mailClient.Send(message);
        message.Dispose();
    }

我得到了以下错误:

I got the following error:

一个连接尝试失败,因为连接的方没有在一段时间后正确响应或已建立的连接失败,因为连接主机未能响应209.191.108.191:25

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 209.191.108.191:25

推荐答案

您正在使用的错误的服务器。您将需要使用SMTP设置。

You are using the wrong server. You will need to use the SMTP settings.

试试这个服务器: plus.smtp.mail.yahoo.com 他们的网站上注意到,该主机SSL

try this server: plus.smtp.mail.yahoo.com Their site notes this host as SSL.

private void SendMail(string from, string body) 
{ 
    string mailServerName = "plus.smtp.mail.yahoo.com"; 
    int mailServerPort = 465;
    string toAddress = "aditya15417@yahoo.com";
    string subject = "feedback";

    string username = "user";
    string password = "password";

    SmtpClient mailClient = new SmtpClient(mailServerName, 
                                           mailServerPort); 
    mailClient.Host = mailServerName; 
    mailClient.Credentials = new NetworkCredential(username, 
                                                   password);
    mailClient.EnableSsl = true;

    using (MailMessage message = new MailMessage(from, 
                                                 toAddress, 
                                                 subject, 
                                                 body))
        mailClient.Send(message); 
} 

这篇关于code发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆