<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Web.Services" %>
<%@ Import Namespace="System.Web.UI" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Page.Controls.Clear();
}
[WebMethod(EnableSession = true)]
public static object SendMail(string name, string mobile, string mail, string sex)
{
string result = "1";
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("xxxxx@gmail.com");
msg.To.Add("aaaaa@gmail.com");
//這裡可以隨便填,不是很重要
msg.From = new MailAddress(mail, name, System.Text.Encoding.UTF8);
/* 上面3個參數分別是發件人地址(可以隨便寫),發件人姓名,編碼*/
msg.Subject = "築禾豐-有興趣(" + name + ")";//郵件標題
msg.SubjectEncoding = System.Text.Encoding.UTF8;//郵件標題編碼
//郵件內容
msg.Body = "築禾豐:<br/>";
msg.Body += "姓名:" + name + "<br/>";
msg.Body += "電話:" + mobile + "<br/>";
msg.Body += "信箱:" + mail + "<br/>";
msg.Body += "性別:" + sex + "<br/>";
msg.Body += "寄信時間:" + DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss") + "<br/>";
msg.Body += "<br/>";
msg.Body += "Best Regards";
msg.BodyEncoding = System.Text.Encoding.UTF8;//郵件內容編碼
//msg.Attachments.Add(new Attachment(@"D:\test2.docx")); //附件
msg.IsBodyHtml = true;//是否是HTML郵件
//msg.Priority = MailPriority.High;//郵件優先級
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("xxxx@gmail.com", "password"); //這裡要填正確的帳號跟密碼
client.Host = "smtp.gmail.com"; //設定smtp Server
client.Port = 25; //設定Port
client.EnableSsl = true; //gmail預設開啟驗證
client.Send(msg); //寄出信件
client.Dispose();
msg.Dispose();
}
catch (Exception ex)
{
result = ex.ToString();
}
return new { Result = result };
}
</script>
第一次看到這個方法!
不知道在網頁上看原始碼會變怎樣子0_0
如果是這樣寫的話是前面的page_load
會先執行還是後面的