經STMP發送電郵 - 簡單

来源:互联网 发布:mac mini 2014 换内存 编辑:程序博客网 时间:2024/05/02 00:25
代碼如下
一個按鈕btnSend,
一個文本框txtbox
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Net.Mail; public partial class NWorkFlow_SENDTEST : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {     }    protected void btnSend_Click(object sender, EventArgs e)    {         MailAddress to = new MailAddress("XXXX@sZZZ.com");                MailAddress from = new MailAddress("XXXX@sZZZ.com");                    MailMessage message = new MailMessage(from, to);            message.Subject = "Using the new SMTP client.";            message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";            // Use the application or machine configuration to get the             // host, port, and credentials.            SmtpClient client = new SmtpClient();        client.Host="XXX2.sZZZ.com";        client.Port=25;        client.UseDefaultCredentials = true;        txtbox.Text = "Sending an e-mail message to {0} at {1} by using the SMTP host={2}.";                    try {              client.Send(message);            }            catch (Exception ex) {             txtbox.Text="Exception caught in CreateTestMessage3(): {0}"+ ex.ToString();                        }              }}
0 0
原创粉丝点击