Executing JavaScript while sending email?

O

Oltmans

Hi All,

I'm trying to send an HTML email from my asp.net 2.0 application. I
want to show an "alert" message when user opens up my email message
using JavaScript. Though I've been able to send email but I am
*unable* to show an alert message using JavaScript. Any ideas, please
enlighten me. Thanks.


Here is my code
--------------------------
SmtpClient smtpClient = new SmtpClient();

MailMessage objMail = new MailMessage();
//From Address will be assigned from the e-mail specified
in the From TextField

MailAddress objMail_fromaddress = new
MailAddress("(e-mail address removed)");

//To Address will be assigned from the e-mail specified in
the To TextField

MailAddress objMail_toaddress = new
MailAddress("(e-mail address removed)");



//Assigning From address to the MailMessage class

objMail.From = objMail_fromaddress;



//Assigning To address to the MailMessage class as a
collection

objMail.To.Add(objMail_toaddress);

objMail.Subject = ".NET email";
StringBuilder sb = new StringBuilder();
sb.Append("<html>");
sb.Append("<head>");
sb.Append("<script type=\"text/javascript\">");
sb.Append("window.onload=hello;");
sb.Append("function hello(){alert(\"Hi there, What's up
\");}");
sb.Append("</head>");
sb.Append("<body>");
sb.Append("<form><br/>");
sb.Append("<input type=\"text\" id=\"tb\" /></form>");
sb.Append("</body>");
sb.Append("</html>");

objMail.IsBodyHtml = true;
objMail.Body = sb.ToString();
objMail.Priority = MailPriority.High;
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.Credentials = new
System.Net.NetworkCredential("(e-mail address removed)", "mypassword");

try
{
smtpClient.Send(objMail);
//HttpContext.Current.Response.Redirect("http://
localhost");
}
catch (Exception exc)
{
HttpContext.Current.Response.Write("Send failure: " +
exc.ToString());
}
 
A

Alvin Bruney [MVP]

I'm not sure window.onload would work so you may have to try the body tag's
onload event
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Oltmans said:
Hi All,

I'm trying to send an HTML email from my asp.net 2.0 application. I
want to show an "alert" message when user opens up my email message
using JavaScript. Though I've been able to send email but I am
*unable* to show an alert message using JavaScript. Any ideas, please
enlighten me. Thanks.

I don't think that you can find any mail client that will support
Javascript in a mail.

You can use html format in a mail, but that doesn't turn the mail into a
web page, it's still just a mail message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Email problem 3
sending email problem 1
Sending email with ASP.NET 2.0 1
emailsender 0
Trying to send an email 1
Send Email Timeout... 2
Help - Failure sending email 1
SmtpClient Problem 4

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top