JMail.NET V1.1 发送邮件

      自己写的一个小软件,想做个邮件提示的功能模块,找了半天,觉得JMail这个挺不错的,应该能满足自己的要求,于是就去下载了JMail.NET V1.1。

       Dimac在网站上给了些JMail的例子,看起来还是比较简单的,也不复杂,但是自己用起来的情况去不是这样,看和做确实就是两回事情啊!

       网上的很多JMail.NET的例子,在现在的V1.1中都不能运行了(还是有参考价值的),所以只能自己动手来做了 。

       倒腾了一下午,终于能顺利发送邮件了。

 


        程序的代码:
namespace JMailTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Message message = new Message();

            //设置发件人地址
            message.From.Email = "*@*.com";

           
            // 添加一个收件人地址
            message.To.Add(new Address("*@*.com"));

           
            // 设置主题和内容
            message.Charset = Encoding.UTF32;
            message.Priority = Priority.Medium;
            message.Subject = "Hello, world!";
            message.BodyText = "Test JMail.";
           

            // 添加一个附件
            message.Attachments.Add(@"d:/in1.txt");

 

            // 发送消息
            try
            {
                Smtp smtp = new Smtp();
                smtp.UserName = "*@*.com";
                smtp.Password = "***";
                smtp.HostName = "smtp.*.com";
                smtp.Port = 25;
                smtp.Domain = "*.com";
                smtp.LogStream = Console.OpenStandardOutput();
                smtp.Authentication = SmtpAuthentication.Login;
                smtp.Send(message);
                Console.WriteLine("The message has been sent.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to send message: {0}", ex.Message);
            }

        }
    }
}
这只是个简单发送邮件的例子,下面在做个简单接受邮件的例子看看。

天天倒腾倒腾,还是有点乐子的。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章