0

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);
}
Omar
  • 32,302
  • 9
  • 69
  • 112
toy4fun
  • 839
  • 2
  • 14
  • 33
  • Browsing with a Windows version of Safari produce the same result - the HTML page is created on the server but doesn't gets send. When browsing with Safari via the localhost (running in VS2010) - everything works well. Is the problem in the webserver itself? – toy4fun Aug 19 '13 at 11:53
  • What web server are you using? – Itai Bar-Haim Aug 19 '13 at 20:07
  • Also, you only mentioned IE, what about other browsers like Chrome and Firefox? does it work with them? – Itai Bar-Haim Aug 19 '13 at 20:09
  • You've only shared the code itself. I guess it is inside some "POST" method. What's more important is - did you set any attributes on that method? See this question for example: http://stackoverflow.com/questions/15017412/safari-posting-blank-form-to-my-server – Itai Bar-Haim Aug 19 '13 at 20:14

1 Answers1

0

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

toy4fun
  • 839
  • 2
  • 14
  • 33