STMP发送邮件(可以运行在winform和asp.net下)

MailMessage Msg = new MailMessage("\"四季鲜花\" <发件箱>", "\"名称\" <收件箱>");
                //定义一封邮件,参数是发件人地址和收件人地址
                Msg.Subject = "四季鲜花下单成功!";//邮件的主题
                Msg.IsBodyHtml = false;//邮件是否为HTML格式的
                Msg.Body = "您已成下单成功! 订单编号是:" + v + ",如有疑问请去 www.f1188.com上查询";
                SmtpClient objEmail = new SmtpClient("smtp.qq.com"); //SMTP服务器主机名,比如GMail的smtp.gmail.com
                objEmail.Credentials = new NetworkCredential("[email protected]", "密码");
                objEmail.EnableSsl = false; //是否启用加密连接,GMail的邮箱必须用加密,其他不支持的邮箱用false
                objEmail.Send(Msg);

具体事例

private void btnSend_Click(object sender, EventArgs e)
        {
            SendMail();
        }

        private void SendMail()
        {
            string from = "[email protected]";
            string to = "[email protected]";
            string subject = "Tank Bug提交";
            string body = txtMail.Text;
            string server = "smtp.163.com";
            MailMessage message = new MailMessage(from, to, subject, body);
            SmtpClient client = new SmtpClient(server);
            client.Credentials = new NetworkCredential("qq1989hn", "qq1989");
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            MessageBox.Show("邮件发送成功!");
            this.Close();
        }


你可能感兴趣的:(STMP发送邮件(可以运行在winform和asp.net下))