我創建了一個服務來發送郵件,但收到錯誤:試圖建立一個服務來發送郵件,但收到錯誤
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.IO;
using System.Net;
using System.Net.Mail;
/// <summary>
/// Summary description for Thankyou
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Thankyou : System.Web.Services.WebService
{
public Thankyou()
{
//Uncomment the following line if using designed components
//InitializeComponent();
using (MailMessage mm = new MailMessage("[email protected]", "[email protected]"))
{
mm.Subject = "Event Inquiry";
mm.Body = @"<html>
<head><title>[#text:@@hotelname#] Event Inquiry Form</title></head>
<body>
<h1 style = ""font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:normal; font-size:14px; ""> You have received an email via the <b>[Culver Hotel </b> Event Inquiry form.</h1>
<h2 style = ""font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:normal; font-size:12px;"" >
<b> From: </b>[#text:contact_name#] <a href=""mailto:[#text:contact_email#]"" >[#text:contact_email#]</a><br>
<b> Phone: </b> [#text:contact_phone#]<br>
<b> Requested Date: </b> [#text:rfp_requestmonth#] [#text:rfp_requestdate#],[#text:rfp_requestyear#]<br>
<b> Requested Time: </b> [#text:requested_time#]<br>
<b> Number of Guests: </b> [#text:number_guests#]<br>
<b> Comments: </b><br> [#text:contact_comments#]
</h2>
</body>
</html>";
//if (fuAttachment.HasFile)
//{
// string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
// mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
//}
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("[email protected]", "passw0rd");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
//ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
}
[WebMethod]
public string ThanksMail()
{
//return "Hello World";
Dictionary<string, string> name = new Dictionary<string, string>();
name.Add("1", "Sourav Kayal");
name.Add("2", "Ram mishra");
string myJsonString = (new JavaScriptSerializer()).Serialize(name);
return myJsonString;
}
}
我得到一個錯誤,在這一點上:smtp.Send(mm);
,但HTML似乎是正確的。
任何幫助將不勝感激。
發佈錯誤本身將會非常有助於試圖幫助你的ppl – stevenvanc