使用iPhone浏览时,SmtpClient无法正常工作

时间:2013-08-19 08:58:46

标签: jquery-mobile gmail smtpclient

我开发了一个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);
}

1 个答案:

答案 0 :(得分:0)

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