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等其他浏览器呢?它与他们合作吗? –