Pergunta

I've developed an aspx page which creates an HTML page from an ASPX page and email it.
The client code uses jQuery Mobile. The server code uses SmtpClient in order to send the email.
When browsing with IE, everything is working well.
When browsing with the iPhone browser, the HTML page is created on the server but doesn't gets send.

The code:

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);
}
Foi útil?

Solução

This was eventually solved by using jQuery $("#form1").submit(); instead of the regular this.form1.submit(); in the ASPX page.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top