asp.net之发送邮件

来源:互联网 发布:vip视频软件 编辑:程序博客网 时间:2024/05/05 03:25
protected void Button1_Click(object sender, EventArgs e)
{
bool bl = up("1198302243@qq.com", "37594885@qq.com", "this is a test email.", "这是一封测试邮件。</br>有事请联系:<a href='tencent://message/? uin=55521421'>您好:您的帐号为</a>");
        if (bl)
        {
            MessageBox.Show(this, "邮件发送成功");
        }
        else
        {
            MessageBox.Show(this, "邮件发送失败");
        }
}


 public bool up(string MailName, string SendToMailAddress, string Subject, string Body)
    {
        string SmtpMailServer = "smtp.qq.com";
        MailMessage mail = new MailMessage();
        try
        {
            System.Net.Mail.SmtpClient client = new SmtpClient(发件箱邮箱服务器);
            client.Credentials = new System.Net.NetworkCredential("箱用户名", "密码");//本地
            mail.To.Add(SendToMailAddress);// = new MailAddressCollection(SendToMailAddress);
            mail.From = new MailAddress(MailName);
            mail.Subject = Subject;
            mail.Body = Body;
            mail.IsBodyHtml = true;
            client.Send(mail);
            return true;
        }
        catch (Exception ex)
        {
            ex.ToString();
        }
        finally
        {
            mail = null;
        }
        return false; 
    }
原创粉丝点击