方法我有Web服務:電話ASP.NET Web服務從JavaScript
[WebMethod]
public void SendMail(string _name, string _email, string _message)
{
//Create Mail Message Object with content that you want to send with mail.
MailMessage MyMailMessage = new MailMessage("[email protected]", "[email protected]", "This is the mail subject", "Just wanted to say Hello");
MyMailMessage.IsBodyHtml = false;
//Proper Authentication Details need to be passed when sending email from gmail
NetworkCredential mailAuthentication = new NetworkCredential("[email protected]", "xxxxxxxxx");
//Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
//For different server like yahoo this details changes and you can
//get it from respective server.
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
//Enable SSL
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(MyMailMessage);
}
和我有一個HTML頁面。我怎樣才能從我的HTML頁面調用這個函數? (此功能必須將郵件發送到電子郵件)
[$ .ajax和webmethod/pagemethods]的可能重複(http://stackoverflow.com/questions/14 58969/ajax-and-webmethod-pagemethods) –
你是否願意添加jQuery庫? –
@Mr。失望 - 我不認爲這是該頁面的重複。 –