Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Executing JavaScript while sending email?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oltmans - 06 Oct 2007 12:47 GMT
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("abce@gmail.com");

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

           MailAddress objMail_toaddress = new
MailAddress("abc@live.com");

           //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("abce@gmail.com", "mypassword");

           try
           {
               smtpClient.Send(objMail);
               //HttpContext.Current.Response.Redirect("http://
localhost");
           }
           catch (Exception exc)
           {
               HttpContext.Current.Response.Write("Send failure: " +
exc.ToString());
           }
Alvin Bruney [MVP] - 07 Oct 2007 01:06 GMT
I'm not sure window.onload would work so you may have to try the body tag's
onload event

Signature

Regards,
Alvin Bruney
------------------------------------------------------
Shameless Author Plug
OWC Black Book 2nd Edition
Exclusively on www.lulu.com/owc
$24.99

> Hi All,
>
[quoted text clipped - 65 lines]
> exc.ToString());
>            }
Göran Andersson - 07 Oct 2007 02:24 GMT
> Hi All,
>
[quoted text clipped - 3 lines]
> *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.

Signature

Göran Andersson
_____
http://www.guffa.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.