0

我开发了一个 aspx 页面,它从 ASPX 页面创建一个 HTML 页面并通过电子邮件发送它。
客户端代码使用 jQuery Mobile。服务器代码使用 SmtpClient 来发送电子邮件。
使用 IE 浏览时,一切正常。
使用 iPhone 浏览器浏览时,HTML 页面会在服务器上创建,但不会发送。

编码:

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("username@gmail.com");
mail.To.Add(new MailAddress("someone@gmail.com"));
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("username@gmail.com", "password");
    smtpClient.EnableSsl = true;
    smtpClient.Send(mail);
}
4

1 回答 1

0

这最终通过使用 jQuery而不是ASPX 页面$("#form1").submit(); 中的常规来解决。this.form1.submit();

于 2013-09-02T13:30:55.460 回答