过客 ——在我死后,哪管它洪水滔天!
System.Net.Mail邮件发送
来自:lpyedge@ 过客 日期:2007-12-8 1:03:48 全文阅读:loading... 分类:技术
【摘要】

用了4个小时才整明白这么简单的一个东西,用gmail的企业邮箱怎么发信都不成功,最后终于发现了,原来是端口的问题.不能用465,要用587,天啊~,代码共享一下了
调用
Mailto.Mailto mail = new Mailto.Mailto("service@domin.com", "Hello", "test@test.com", "hello !!!!", "smtp.gmail.com", 587, true, "service@domin.com", "password");
            if (mail.Send())
            {
                lc.WebMessageBox("Your Password Has Been Sent To Your Email", Page, true);
            }

mailto类
namespace Mailto
{
    using System;
    using System.Net;
    using System.Net.Mail;



【全文】

用了4个小时才整明白这么简单的一个东西,用gmail的企业邮箱怎么发信都不成功,最后终于发现了,原来是端口的问题.不能用465,要用587,天啊~,代码共享一下了
调用
Mailto.Mailto mail = new Mailto.Mailto("service@domin.com", "Hello", "test@test.com", "hello !!!!", "smtp.gmail.com", 587, true, "service@domin.com", "password");
            if (mail.Send())
            {
                lc.WebMessageBox("Your Password Has Been Sent To Your Email", Page, true);
            }

mailto类
namespace Mailto
{
    using System;
    using System.Net;
    using System.Net.Mail;

    public class Mailto
    {
        private MailMessage Mail = new MailMessage();
        private SmtpClient SmtpServer = new SmtpClient();
        public Mailto(string mFrom, string mSubjest, string mTo, string mBody, string mSmtpServer, int mSmtpPort, bool mSmtpSSL, string mUsername, string mPassword)
        {
            MailAddress mFromadd = new MailAddress(mFrom);
            Mail.From = mFromadd;
            Mail.Subject = mSubjest;
            Mail.To.Add(mTo);
            Mail.Body = mBody;
            SmtpServer.Host = mSmtpServer;
            SmtpServer.Port = mSmtpPort;
            SmtpServer.EnableSsl = mSmtpSSL;
            SmtpServer.UseDefaultCredentials = true;
            SmtpServer.Credentials = new NetworkCredential(mUsername, mPassword);
            SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
        }

        public string mHtml(bool html)
        {
            Mail.IsBodyHtml = html;
            if (html)
            {
                return "Html";
            }
            else
            {
                return "Text";
            }
        }

        public bool Send()
        {
            try
            {
                SmtpServer.Send(Mail);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}

 

【全文结束】
【评论1】时间:2008-6-18 18:21:29作者:zoe
我用企业邮箱发的怎么试都还是不行!
如果看到回复请加我mfbtm@hotmail.com,请您指教!
发表您的评论:
署名:记住我
主页:
内容: