Send Javascript by email

Asked

Viewed 913 times

3

I have a code in C# that sends emails with HTML, until then ok, the problem is that I can not send scripts (JS). Yes, I understand why, must be security reasons. But there is no way burlar or do otherwise? -- With no malicious intent. My code:

using (MailMessage mail = new MailMessage())
        {
            mail.From = new MailAddress("[email protected]");
            mail.To.Add("[email protected]");
            mail.Subject = "xxx";
            mail.Body = @"<script>SCRIPT aqui.</script>";
            mail.IsBodyHtml = true;

            using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
            {
                smtp.Credentials = new NetworkCredential("[email protected]", "xxx");
                smtp.EnableSsl = true;
                smtp.Send(mail);
            }
        }
  • As you asked if this cannot be done otherwise, what would be the function of the script?

  • @dvd Just show an alert. I know I can display the message in HTML,but I wanted to run a alert in JS, just to see if it would work.

  • 2

    So, the email servers, for example Gmail, Hotmail and the like, for security don’t let any of that run, there’s no way around it, the only way, I see, would be to use some email receiver that doesn’t depend on these e-servicesmail, yes, because they use some kind of stripHtml when receiving the message, IE, your message arrives in any third party reader or others, already without these scripts! I believe it is a demand in vain, find alternatives!

  • @Draw what your goal is with this?

1 answer

2


You can always send HTML script blocks along with your email, the problem is that it will be removed on the server or will not run. The vast majority of email clients will remove or disable script execution for security reasons, regardless of whether your code is malicious or not.

In the early 2000s, this was still possible. Even some clients like Outlook and Exchange ran up to Vbscript and this was very risky in windows environment.

However, depending on what you expect and think you need Javascript to achieve, it can be done in other ways. Like for example the read confirmation, which can be done by including a parameter in the upload url of an image and monitor it in the server log (provided the user enables and accepts to display the images).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.