问题描述
如何下载我的电子邮件帐户的电子邮件或如何使用pop和smtp发送? .NET是否为这些类型的操作提供了准备好的对象?请,我需要使此功能正常工作..
借口是弱者的避难所...我们就是我们的选择.
How can I download the emails of my email account or send using the pop and smtp? Does .NET provide ready objects for these type of operation? Please, I need to get this functionality working..
Excuses are the refuge of the weak... We are who we choose to be.
推荐答案
公共 无效 SendMail()
{
SmtpClient客户= 新 SmtpClient();
MailAddress sendTo = 新 MailAddress(" [email protected]" );
MailAddress 来自 = new MailAddress(" [email protected]" );
MailMessage消息= 新 MailMessage(来自,sendTo);
message.IsBodyHtml = false ;
message.Subject = 测试" ;
message.Body = 这是否有效?" ;
NetworkCredential nc = 新 NetworkCredential(" [email protected]" ,您的Gmail密码" );
client.Host = " smtp.gmail.com" ;
client.UseDefaultCredentials = false ;
public void SendMail()
{
SmtpClient client = new SmtpClient();
MailAddress sendTo = new MailAddress("[email protected]");
MailAddress from = new MailAddress("[email protected]");
MailMessage message = new MailMessage(from, sendTo);
message.IsBodyHtml = false;
message.Subject = "Testing";
message.Body = "Is this working?";
NetworkCredential nc = new NetworkCredential("[email protected]","your gmail password");
client.Host = "smtp.gmail.com";
client.UseDefaultCredentials = false;
client.port = 25;
client.Credentials = nc;
client.EnableSsl = true ;
尝试
{
client.Send(message);
MessageBox.Show("酷!" );
}
捕获(异常除外)
{
MessageBox.Show(ex.Message,失败" );
}
}
client.port=25 ;
client.Credentials = nc;
client.EnableSsl = true;
try
{
client.Send(message);
MessageBox.Show("Cool!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Fail");
}
}
这篇关于如何在C#中使用pop和smtp下载和发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!