首页 新闻 搜索 专区 学院

asp.net如何实现给用户发邮件的功能???

0
悬赏园豆:200 [已关闭问题]

我要给 942426801@qq.com 这个用户发一个邮件 内容是 密码: aaaaaa  请问如何实现这个功能,请给出一个可以实现这个功能的代码,我只要实现这个功能的代码就行了,请测试过后在贴出代码!

非常感谢!!

问题补充: 给 zhangxinpingit@163.com zhangxinpingit@yahoo.cn zhangxinpingit@sina.com zhangxinpingit@gmail.com 这几个邮箱发也可以! 高手们请指点我哈!
O(∩_∩)O~的主页 O(∩_∩)O~ | 初学一级 | 园豆:5
提问于:2009-03-25 09:27
< >
分享
其他回答(3)
0

public static bool SendMail(string address, string subject, string body, bool isBodyHtml)
        {
            StringDictionary dic = SettingUtil.LoadSettings();

            if (dic == null)
                return SendMailResult.Fail;

            string host = dic["smtpserver"];
            string port = dic["smtpserverport"];
            string ssl = dic["enablessl"];
            string userid = dic["smtpusername"];
            string pwd = dic["smtppassword"];
            string replyto = dic["replyto"];

            MailMessage objMail = new MailMessage();
            objMail.To.Add(address);
            objMail.From = new MailAddress(userid, userid, Encoding.UTF8);
            objMail.Subject = subject;
            objMail.SubjectEncoding = Encoding.UTF8;
            objMail.Body = body;
            objMail.IsBodyHtml = isBodyHtml;
            objMail.Priority = MailPriority.High;
            if (!string.IsNullOrEmpty(replyto))
                objMail.ReplyTo = new MailAddress(replyto);

            SmtpClient client = new SmtpClient();
            client.Credentials = new NetworkCredential(userid, pwd);

            client.Host = host;
            client.Port = int.Parse(port);
            if (ssl.Equals("false", StringComparison.CurrentCultureIgnoreCase))
                client.EnableSsl = false;
            else
                client.EnableSsl = true;

            try
            {
                client.Send(objMail)

           }

                return true;
            }
            catch (SmtpException ex)
            {
                                    return false;
                }
            }

GUO Xingwang | 园豆:3885 (老鸟四级) | 2009-03-25 09:34
0
winzheng | 园豆:8797 (大侠五级) | 2009-03-25 10:16
0

建一个发email的类,然后把你要发信息与地址传进去不就可以发了吗? .net发email有很简单的,网上很多这样的代码,可以用自己的SMTP服务器,也可以用163,21cn,qq这些SMTP

风浪 | 园豆:2861 (老鸟四级) | 2009-03-25 10:53
-1

Web.config

Default.aspx

Default.aspx.cs

App_Code/Utility.cs

App_Code/AlertMessage.cs

WizardWu | 园豆:1402 (小虾三级) | 2009-03-25 11:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册