0
我開發了一個aspx頁面,它可以從ASPX頁面創建一個HTML頁面併發送給它。
客戶端代碼使用jQuery Mobile。服務器代碼使用SmtpClient來發送電子郵件。
使用IE瀏覽器時,一切正常。
使用iPhone瀏覽器進行瀏覽時,HTML頁面將在服務器上創建,但不會發送。使用iPhone瀏覽時SmtpClient不工作
代碼:
TimeZoneInfo israelTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Israel Standard Time");
DateTime utc = DateTime.UtcNow;
DateTime israel = TimeZoneInfo.ConvertTimeFromUtc(utc, israelTimeZone);
string fileName = string.Format("Report_{0}.htm", israel.ToString("ddMMyy_HHmmss"));
StringWriter stringWriter = new StringWriter();
Server.Execute(@"..\Report.aspx", stringWriter);
string reportBody = stringWriter.ToString();
using (StreamWriter streamWriter = File.CreateText(Server.MapPath(@"..\Reports\" + fileName)))
{
streamWriter.WriteLine(reportBody);
streamWriter.Close();
}
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add(new MailAddress("[email protected]"));
mail.Subject = "New report";
mail.IsBodyHtml = true;
mail.Body = "<html dir='rtl'><head><meta content='text/html; charset=utf-8' http-equiv='Content-Type' /><meta content='he' http-equiv='Content-Language' />" +
"<title>title</title><style type='text/css'>body {font-family: Arial; font-size: 13px;}</style></head><body><p>bla bla bla</p></body></html>";
Attachment attachment = new Attachment(Server.MapPath(@"..\Reports\" + fileName));
mail.Attachments.Add(attachment);
using (SmtpClient smtpClient = new SmtpClient())
{
smtpClient.Host = "smtp.gmail.com";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("[email protected]", "password");
smtpClient.EnableSsl = true;
smtpClient.Send(mail);
}
使用Windows版本的Safari進行瀏覽會產生相同的結果 - HTML頁面在服務器上創建,但不會發送。當通過本地主機(在VS2010中運行)通過Safari瀏覽時 - 一切正常。 Web服務器本身存在問題嗎? – toy4fun
你在用什麼網頁服務器? –
另外,你只提到IE,Chrome和Firefox等其他瀏覽器呢?它與他們合作嗎? –