[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Using javascript inside an HTML Email?

Posted on 2006-11-13
12
Medium Priority
?
366 Views
Last Modified: 2008-02-01
I'm attempting to implement a copy URL function inside the body of an HTML email being sent by ASP.Net.

This is what I'm working with so far:

            Dim smtpClient As SmtpClient = New SmtpClient()
            Dim message As MailMessage = New MailMessage()
            Dim CopyPath As String = "onclick=javascript: window.clipboardData.setData(Text," & SavePath & ")"


            'Format email body, this is pretty self explanatory. Build one big string with HTML formatting and then pass it l8r
            Dim EmailBody As String = ""
            EmailBody &= "<html>"
            EmailBody &= "<body>"
            EmailBody &= "<head>"
            EmailBody &= "<span style=""font-size:14pt; font-face:arial; font-weight:bold"">"
            EmailBody &= "Workflow has saved a text file you can import into a LegalKey search."
            EmailBody &= "</span><br/><hr><br/>"
            EmailBody &= "<span style=""font-size:12pt; font-face:arial; font-weight:bold"">"
            EmailBody &= " To view this file <a href=" & SavePath & ">click here</a>"
            EmailBody &= "</span><br/><br/>"
            EmailBody &= "<span style=""font-size:12pt; font-face:arial; font-weight:bold"">"
            EmailBody &= " To copy the location of this file <a href=" & CopyPath & ">click here</a>"
            EmailBody &= "</span><br/><br/>"


I have messed around with a lot of different syntax options, but I either get errors or it just returns " & SavePath & "  into the clipboard.

Thanks.


0
Comment
Question by:ApexCo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
12 Comments
 
LVL 9

Expert Comment

by:kraffay
ID: 17933015
Add a single quote around the href attribute:

EmailBody &= " To view this file <a href='" & SavePath & "'>click here</a>"
0
 
LVL 8

Author Comment

by:ApexCo
ID: 17933537
I'm sorry, I didn't specify where the problem was exactly. The viewing portion works fine, it's the attempt to copy the path to the clipboard that is giving me problems.

So this:

Dim CopyPath As String = "onclick=javascript: window.clipboardData.setData(Text," & SavePath & ")"

and this

EmailBody &= " To copy the location of this file <a href=" & CopyPath & ">click here</a>"



Thanks.
0
 
LVL 8

Author Comment

by:ApexCo
ID: 17933866
You know, I just realized something.

This isn't opening in IE, it's opening in Outlook 2003. Is this even possible from inside of an email?

Thanks.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 17937561
Are you setting BodyFormat to MailFormat.Html ?

Bob
0
 
LVL 8

Author Comment

by:ApexCo
ID: 17937999
Yes, I am.

'Body can be Html or text format, specify true if it is html message
            message.IsBodyHtml = True
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17938009
Did you try this?

    message.BodyFormat = MailFormat.Html

Bob
0
 
LVL 8

Author Comment

by:ApexCo
ID: 17938050
No, but I just did.

It's telling me that message.bodyformat isn't part of 2.0

There is a message.BodyEncoding though, but nothing pertaining to HTML inside the bodyencoding.
0
 
LVL 8

Author Comment

by:ApexCo
ID: 17938058
FWIW, I have used this before to send HTML messages, without problems. It's just the whole javascript thing that has me hung up.
0
 
LVL 8

Author Comment

by:ApexCo
ID: 17938082
Man I wish you could edit...

This is as far as I have gotten with making the syntax as correct as I know how.

Dim CopyPath As String = """javascript:window.clipboardData.setData('Text','" & SavePath & "')"""

And now when I click on my link inside the email I get a "unspecified error".
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17938133
Try:

String.Format("<script language='{0}'>window.clipboardData.setData('Text', '{1}'); </script> ", "JavaScript", SavePath)

Bob
0
 
LVL 8

Author Comment

by:ApexCo
ID: 17938251
Nope, but I see what you are trying to do with that, clever :) *makes note for future reference*

Now when you click on the link it opens a "locate link browser" window...

I'm wondering if the problem isn't the javascript, but how I'm trying to use it?

EmailBody &= " To copy the location of this file <a href=" & CopyPath & ">click here</a>"

That CopyPath variable represents the string.

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17946339
Yeah, I am not sure if that is going to work, but I am not 100% sure.

Bob
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question