Saturday, October 11, 2008

Question:How can u insert javascript in mail body using system.net.mail or system.web.mail

Hi Guys,


I have created a background service which send the email of birthday list of all employees who's birthday's are fall on present month. on 1st of every month to the manger .once manager receives email and clicks add reminder button on the email which he has received then he should be able to add that details as a reminder in outlook.


So presently I am attaching the client script also the same email body and calling that script on hyper link click. But when manager receives email that hyper link is displaying like a text . but see the original content of the email by selecting the "see original message" and copy the same content as ".html" then it is working as expected. ---it is showing the href and by click on that the information added to outlook. Same body is not working on the mail.


Please give me some inputs on this.


Thanks in advance

Naveen.





discussion1:
Most mail clients will not allow for javascript inside the email body.


discussion2:
could please send any examles on it. i just used the below code to send the email with embeded javascript.

with the below code i am able to send the email with one buttion. but while clicking on it no action is performed. but if you see the orginal content of the mail and pasted this in another notepad and save it something like "1.html" and open it. then javascript is firing . what is the main differnce while it is in email body. is there have any alternatives to work on client side.




discussion3:
using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Web.Mail;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

try

{

MailMessage msg = new MailMessage();

msg.From = naveen.bandla@msn.com;

msg.To = naveen.bandla@gmail.com;

msg.Subject = "test for smtp";

msg.BodyFormat = MailFormat.Html;

msg.Body = " function onclickme(){alert(\"hai\")} hai";

SmtpMail.SmtpServer = "";

SmtpMail.Send(msg); Response.Write("mail send"); }

catch(Exception ex) { Response.Write(ex.Message); } }

} Read more : Fingerprint Scanner Supplier in Dubai

No comments: