本文介绍了如何在C#中使用pop和smtp下载和发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何下​​载我的电子邮件帐户的电子邮件或如何使用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下载和发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 18:14