How to insert URL in ASP.Net e-mail message

P

Peter Afonin

Hello,

I created an e-mail form pretty much as described in this article:
http://www.4guysfromrolla.com/webtech/080801-1.shtml. It works great, but I
cannot figure out one thing:

I need to insert a URL at the bottom of the message body. How would I do
this? If I insert just HTML - it displays HTML. I tried Response.Write
method, StringBuilder and HTMLTextWriter classes - no luck so far.

I would appreciate your advice on this.

Thank you,
 
G

George

Not sure if this is what you're looking for, but this is how I build and send an e-mail message to
myself. Maybe it will give you some ideas.

Private Sub sendMail(ByVal msgTxt As String)
Dim msg As MailMessage = New MailMessage()
SmtpMail.SmtpServer = "xxxx.xxxx.com"
msg.Body = msgTxt
msg.From = "(e-mail address removed)"
msg.To = "(e-mail address removed)"
msg.Subject = "Some Subject!"

Try
SmtpMail.Send(msg)
Catch
End Try
End Sub

Private Sub SomeOtherSub()
Dim userAgent As String
Dim referringPage As String

If Not Request.UserAgent Is Nothing Then
userAgent = Request.UserAgent
Else
userAgent = "No user agent available!"
End If

'This is how I get a URL to string
If Not Request.UrlReferrer Is Nothing Then
referringPage = Request.UrlReferrer.ToString()
Else
referringPage = "Direct access by bookmark, local-based e-mail link, etc."
End If

Dim msgTxt As String = vbCrLf & _
"Browser Name: " & Request.Browser.Browser & vbCrLf & _
"Browser Type: " & Request.Browser.Type & vbCrLf & _
"Browser Version: " & Request.Browser.Version & vbCrLf & _
"Browser Platform: " & Request.Browser.Platform & vbCrLf & _
"Accepts Cookies: " & Request.Browser.Cookies & vbCrLf & _
"User Agent: " & userAgent & vbCrLf & _
"User Host Address: " & Request.UserHostAddress.ToString & vbCrLf & _
"User Host Name: " & Request.UserHostName & vbCrLf & _
"Referring URL: " & referringPage

If Not Request.Cookies("userInfo") Is Nothing Then
msgTxt = msgTxt & vbCrLf & vbCrLf & _
"This Visit: " & Request.Cookies("userInfo")("thisVisit") & vbCrLf & _
"Last Visit: " & Request.Cookies("userInfo")("lastVisit") & vbCrLf & _
"Total Visits: " & Request.Cookies("userInfo")("numVisits") & vbCrLf
End If

sendMail(msgTxt)
End Sub

I use the Try\Catch\End Try just in case the mail server is down. If it is, I just pass on getting
that particular message because I can live without it. So I don't really need to trap that error, I
just don't want my app to crash. User agent and URL Referrer will crash my app, too, so that is why
I'm checking them first. Maybe some of the others will, too, but not sure.

Hope that helped a little. I'm just learning this stuff, so there is probably a better way to do it.
I've gotten a lot of answers in this NG, so thought I'd try to give back a little. ;-)

George
 
P

Peter Afonin

Thank you, George.

I need a little different, I guess. I just want to display my company name
at the bottom of the e-mail body as a hyperlink, just like here:
www.mycompanyname.com , so the person could click on it and get to my site.
It should be a simple task, I've just never done this before.

Peter


George said:
Not sure if this is what you're looking for, but this is how I build and send an e-mail message to
myself. Maybe it will give you some ideas.

Private Sub sendMail(ByVal msgTxt As String)
Dim msg As MailMessage = New MailMessage()
SmtpMail.SmtpServer = "xxxx.xxxx.com"
msg.Body = msgTxt
msg.From = "(e-mail address removed)"
msg.To = "(e-mail address removed)"
msg.Subject = "Some Subject!"

Try
SmtpMail.Send(msg)
Catch
End Try
End Sub

Private Sub SomeOtherSub()
Dim userAgent As String
Dim referringPage As String

If Not Request.UserAgent Is Nothing Then
userAgent = Request.UserAgent
Else
userAgent = "No user agent available!"
End If

'This is how I get a URL to string
If Not Request.UrlReferrer Is Nothing Then
referringPage = Request.UrlReferrer.ToString()
Else
referringPage = "Direct access by bookmark, local-based e-mail link, etc."
End If

Dim msgTxt As String = vbCrLf & _
"Browser Name: " & Request.Browser.Browser & vbCrLf & _
"Browser Type: " & Request.Browser.Type & vbCrLf & _
"Browser Version: " & Request.Browser.Version & vbCrLf & _
"Browser Platform: " & Request.Browser.Platform & vbCrLf & _
"Accepts Cookies: " & Request.Browser.Cookies & vbCrLf & _
"User Agent: " & userAgent & vbCrLf & _
"User Host Address: " & Request.UserHostAddress.ToString & vbCrLf & _
"User Host Name: " & Request.UserHostName & vbCrLf & _
"Referring URL: " & referringPage

If Not Request.Cookies("userInfo") Is Nothing Then
msgTxt = msgTxt & vbCrLf & vbCrLf & _
"This Visit: " & Request.Cookies("userInfo")("thisVisit") & vbCrLf & _
"Last Visit: " &
Request.Cookies("userInfo")("lastVisit") & vbCrLf & _
"Total Visits: " &
Request.Cookies("userInfo")("numVisits") & vbCrLf
End If

sendMail(msgTxt)
End Sub

I use the Try\Catch\End Try just in case the mail server is down. If it is, I just pass on getting
that particular message because I can live without it. So I don't really need to trap that error, I
just don't want my app to crash. User agent and URL Referrer will crash my app, too, so that is why
I'm checking them first. Maybe some of the others will, too, but not sure.

Hope that helped a little. I'm just learning this stuff, so there is
probably a better way to do it.
I've gotten a lot of answers in this NG, so thought I'd try to give back a little. ;-)

George
 
G

George

I think if you put it in a string, like I did the referring URL, it will come out as a hyperlink.
When I get the referring URL in my mail message, it is a click-able hyperlink.

Dim companyURL as string = "http://www.mycompanyname.com"

msg.Body = msgTxt & vbCrLf & companyURL

Should work (I think). ;-)

George

Peter Afonin said:
Thank you, George.

I need a little different, I guess. I just want to display my company name
at the bottom of the e-mail body as a hyperlink, just like here:
www.mycompanyname.com , so the person could click on it and get to my site.
It should be a simple task, I've just never done this before.

Peter


George said:
Not sure if this is what you're looking for, but this is how I build and send an e-mail message to
myself. Maybe it will give you some ideas.

Private Sub sendMail(ByVal msgTxt As String)
Dim msg As MailMessage = New MailMessage()
SmtpMail.SmtpServer = "xxxx.xxxx.com"
msg.Body = msgTxt
msg.From = "(e-mail address removed)"
msg.To = "(e-mail address removed)"
msg.Subject = "Some Subject!"

Try
SmtpMail.Send(msg)
Catch
End Try
End Sub

Private Sub SomeOtherSub()
Dim userAgent As String
Dim referringPage As String

If Not Request.UserAgent Is Nothing Then
userAgent = Request.UserAgent
Else
userAgent = "No user agent available!"
End If

'This is how I get a URL to string
If Not Request.UrlReferrer Is Nothing Then
referringPage = Request.UrlReferrer.ToString()
Else
referringPage = "Direct access by bookmark, local-based e-mail link, etc."
End If

Dim msgTxt As String = vbCrLf & _
"Browser Name: " & Request.Browser.Browser & vbCrLf & _
"Browser Type: " & Request.Browser.Type & vbCrLf & _
"Browser Version: " & Request.Browser.Version & vbCrLf & _
"Browser Platform: " & Request.Browser.Platform & vbCrLf & _
"Accepts Cookies: " & Request.Browser.Cookies & vbCrLf & _
"User Agent: " & userAgent & vbCrLf & _
"User Host Address: " & Request.UserHostAddress.ToString & vbCrLf & _
"User Host Name: " & Request.UserHostName & vbCrLf & _
"Referring URL: " & referringPage

If Not Request.Cookies("userInfo") Is Nothing Then
msgTxt = msgTxt & vbCrLf & vbCrLf & _
"This Visit: " & Request.Cookies("userInfo")("thisVisit") & vbCrLf & _
"Last Visit: " &
Request.Cookies("userInfo")("lastVisit") & vbCrLf & _
"Total Visits: " &
Request.Cookies("userInfo")("numVisits") & vbCrLf
End If

sendMail(msgTxt)
End Sub

I use the Try\Catch\End Try just in case the mail server is down. If it is, I just pass on getting
that particular message because I can live without it. So I don't really need to trap that error, I
just don't want my app to crash. User agent and URL Referrer will crash my app, too, so that is why
I'm checking them first. Maybe some of the others will, too, but not sure.

Hope that helped a little. I'm just learning this stuff, so there is
probably a better way to do it.
 
P

Peter Afonin

Thank you, George, I think you're correct, I'll test it. But what if I want
to display it like "My Company" and have a URL behind it? It must be a way
of doing it.

Peter
 
G

George

Sorry, can't help you with that one. I get the same results that you do -- it just drops the HTML
code into the message as though it were text.

George
 
C

Chad Z. Hower aka Kudzu

George said:
Sorry, can't help you with that one. I get the same results that you do
-- it just drops the HTML code into the message as though it were text.

To do it properly so it will be displayed in all clients, as well as not be
filtered by spam filters you have to make an alternative type message. .Net
mail class does NOT support this.

You can use Indy, it supports this and its free.

http://www.indyproject.org/


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 
W

William LaMartin

Thanks for the information that there are Indy components we can use in .Net
now. I used Indy with Delphi 6 and found it quite useful.

I went to the Indy site downloaded the DLL, added it to a test VB.Net
project and created me a Whois lookup application. All very easy, and it
works fine.

I then added it to my .Net tests at my main web site. Unfortunately as soon
as I tried to access the aspx page I get the following error:
System.Security.SecurityException: Security error. Apparently the hosting
company doesn't trust your DLL. I will discuss it with them, but I am
pretty sure it will be a no go.

Their security is such that they will not let ASP.Net create sockets, so I
had hoped to use Indy to get around this. At the same site I have an ISAPI
DLL created with Delphi 6 and Indy that does a Whois lookup with no problem.
 
C

Chad Z. Hower aka Kudzu

William LaMartin said:
I went to the Indy site downloaded the DLL, added it to a test VB.Net
project and created me a Whois lookup application. All very easy, and it
works fine.
Great!

I then added it to my .Net tests at my main web site. Unfortunately as
soon as I tried to access the aspx page I get the following error:
System.Security.SecurityException: Security error. Apparently the
hosting company doesn't trust your DLL. I will discuss it with them,
but I am pretty sure it will be a no go.

So they trust anything you put up in your assembly, but not anything in
external assemblies?
Their security is such that they will not let ASP.Net create sockets, so
I had hoped to use Indy to get around this. At the same site I have an

Ouch - if they wont let ASP.net create sockets, then its doubtful Indy will
work either. It uses the .net sockets internally as well.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 
W

William LaMartin

I have another site where I can test .Net things. There I have a lot more
permissions than I do at my own domain hosted in a shared hosting
environment. If you go to http://216.182.10.243/container/WhoisIndy.aspx ,
you will see the Whois using Indy example working properly.

Well, I guess there is not much use in asking the hosting company if they
will allow the Indy DLL if it uses the .Net sockets, since even if they did,
I still wouldn't be able to use anything from Indy that involved
sockets--which doesn't leave much, I suppose.
 

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

Top