如何在ASP.Net电子邮件中插入URL [英] How to insert URL in ASP.Net e-mail message

查看:153
本文介绍了如何在ASP.Net电子邮件中插入URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我创建了一个电子邮件表单,与本文中描述的完全相同:
http://www.4guysfromrolla.com/webtech/080801-1.shtml 。它工作得很好,但是我不能弄清楚一件事:


我需要在邮件正文的底部插入一个URL。我该怎么做

这个?如果我只插入HTML - 它会显示HTML。我尝试了Response.Write

方法,StringBuilder和HTMLTextWriter类 - 到目前为止没有运气。


我将非常感谢您对此的建议。


谢谢,


-

Peter Afonin

解决方案

不确定这是否是您正在寻找的,但这就是我自己构建和发送电子邮件给

的方式。也许它会给你一些想法。


Private Sub sendMail(ByVal msgTxt As String)

Dim msg As MailMessage = New MailMessage()

SmtpMail.SmtpServer =" xxxx.xxxx.com"

msg.Body = msgTxt

msg.From =" xx ** @ xxxxx.com" ;

msg.To =" xx ** @ xxxx.net"

msg.Subject =" Some subject!"


尝试

SmtpMail.Send(msg)

Catch

结束尝试

End Sub


Private Sub SomeOtherSub()

Dim userAgent As String

Dim referPage As String


如果不是Request.UserAgent则没有那么

userAgent = Request.UserAgent

否则

userAgent ="没有可用的用户代理!

结束如果


''这是我获取字符串的URL

如果不是Request.UrlReferrer则没有

referPage = Request.UrlReferrer.ToString()

否则

referPage ="通过书签,本地电子邮件链接等直接访问

结束如果


Dim msgTxt As String = vbCrLf& _

"浏览器名称:" &安培; Request.Browser.Browser& vbCrLf& _

"浏览器类型:" &安培; Request.Browser.Type& vbCrLf& _

"浏览器版本:" &安培; Request.Browser.Version& vbCrLf& _

"浏览器平台:" &安培; Request.Browser.Platform& vbCrLf& _

"接受Cookie:" &安培; Request.Browser.Cookies& vbCrLf& _

用户代理: &安培; userAgent& vbCrLf& _

"用户主机地址:" &安培; Request.UserHostAddress.ToString& vbCrLf& _

"用户主机名:" &安培; Request.UserHostName& vbCrLf& _

"引用网址:" &安培; referPage


如果不是Request.Cookies(" userInfo")则什么都没有

msgTxt = msgTxt& vbCrLf& vbCrLf& _

此次访问: &安培; Request.Cookies(" userInfo")(" thisVisit")& vbCrLf& _

上次访问: &安培; Request.Cookies(" userInfo")(" lastVisit")& vbCrLf& _

"总访问次数:" &安培; Request.Cookies(" userInfo")(" numVisits")& vbCrLf

结束如果


sendMail(msgTxt)

结束子


我使用Try \Catch \End尝试以防邮件服务器关闭。如果是的话,我只是继续获得

特定的消息,因为我可以没有它。所以我真的不需要陷入这个错误,我不想让我的应用程序崩溃。用户代理和URL Referrer也会崩溃我的应用程序,所以这就是为什么

我先检查它们。也许其他人也会,但不确定。


希望有所帮助。我只是在学习这些东西,所以可能有更好的方法。

我在这个NG中得到了很多答案,所以我想我会试着给回来一点。 ;-)


George


" Peter Afonin" < pv*@speakeasy.net>在留言新闻中写道:eV ************** @ TK2MSFTNGP10.phx.gbl ...

你好,

我创建了一个电子邮件形式与本文中描述的完全相同:
http://www.4guysfromrolla.com/webtech/080801-1.shtml 。它工作得很好,但我无法弄清楚一件事:

我需要在邮件正文的底部插入一个URL。我该怎么办呢?如果我只插入HTML - 它会显示HTML。我尝试了Response.Write
方法,StringBuilder和HTMLTextWriter类 - 到目前为止没有运气。

我很感激你对此的建议。

谢谢你,

-
Peter Afonin




谢谢你,乔治。


我想我需要一点点不同。我只想在电子邮件正文的底部显示我的公司名称

作为超链接,就像这里:
www.mycompanyname.com ,所以此人可以点击它并进入我的网站。

这应该是一项简单的任务我以前从未这样做过。


彼得

"乔治" < ------@----.---& GT;在消息中写道

news:zB ******************* @ bgtnsc05-news.ops.worldnet.att.net ...

不确定这是否是您正在寻找的,但这是我的构建方式,
向我自己发送电子邮件。也许它会给你一些想法。

Private Sub sendMail(ByVal msgTxt As String)
Dim msg As MailMessage = New MailMessage()
SmtpMail.SmtpServer =" xxxx。 xxxx.com"
msg.Body = msgTxt
msg.From =" xx ** @ xxxxx.com"
msg.To =" xx ** @ xxxx.net"
msg.Subject =" Some Subject!"

尝试
SmtpMail.Send(msg)
Catch
结束尝试
End Sub

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

如果Not Request.UserAgent什么都没有那么
userAgent = Request.UserAgent
其他
userAgent ="没有用户代理可用!"
结束如果

''这就是我获取字符串的URL的方法
如果Not Request.UrlReferrer什么都没有那么
referPage = Request.UrlReferrer.ToString()
其他
referPage ="通过书签直接访问,基于本地的电子邮件
链接等。结束如果

Dim msgTxt As String = vbCrLf& _
浏览器名称: &安培; Request.Browser.Browser& vbCrLf& _
浏览器类型: &安培; Request.Browser.Type& vbCrLf& _
浏览器版本: &安培; Request.Browser.Version& vbCrLf& _
浏览器平台: &安培; Request.Browser.Platform& vbCrLf& _
接受Cookies: &安培; Request.Browser.Cookies& vbCrLf& _
用户代理: &安培; userAgent& vbCrLf& _
用户主机地址: &安培; Request.UserHostAddress.ToString& vbCrLf&
_"用户主机名:" &安培; Request.UserHostName& vbCrLf& _
引用网址: &安培; referPage

如果Not Request.Cookies(" userInfo")什么都没有那么
msgTxt = msgTxt& vbCrLf& vbCrLf& _
此次访问: &安培; Request.Cookies(" userInfo")(" thisVisit")
& vbCrLf& _上次访问: &安培;
Request.Cookies(" userInfo")(" lastVisit")& vbCrLf& _总访问次数: &安培;
Request.Cookies(" userInfo")(" numVisits")& vbCrLf结束如果

sendMail(msgTxt)
End Sub

我使用Try \Catch \End尝试以防邮件服务器关闭。如果它是
,我只是传递得到那个特定的消息,因为我可以没有它。所以我真的没有
需要捕获该错误,我只是不希望我的应用程序崩溃。用户代理和URL Referrer也会崩溃我的
应用程序,所以这就是为什么我先检查它们。也许其他一些人也会,但不确定。

希望有所帮助。我只是在学习这些东西,所以有
可能是更好的方法。我已经在这个NG中得到了很多答案,所以我想我会尽量少回馈
。 ;-)
乔治

彼得Afonin < pv*@speakeasy.net>在消息中写道



新闻:eV ************** @ TK2MSFTNGP10.phx.gbl ...

< blockquote class =post_quotes>你好,

我创建了一个电子邮件表单,几乎与本文中描述的一样:
http://www.4guysfromrolla.com/webtech/080801-1.shtml 。它工作得很好,
但我无法弄清楚一件事:

我需要在邮件正文的底部插入一个URL。我该怎么办呢?如果我只插入HTML - 它会显示HTML。我尝试了Response.Write
方法,StringBuilder和HTMLTextWriter类 - 到目前为止没有运气。

我很感激你对此的建议。

谢谢你,

-
Peter Afonin




我想如果你把它在一个字符串中,就像我引用的URL一样,它将作为一个超链接出现。

当我在邮件中获得引用URL时,它是一个可点击的超链接。


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


msg.Body = msgTxt& vbCrLf& companyURL


应该工作(我认为)。 ;-)


George


" Peter Afonin" < pv*@speakeasy.net>在消息新闻中写道:Ow ************** @ TK2MSFTNGP10.phx.gbl ...

谢谢你,乔治。

我想,我需要一点点不同。我只想在电子邮件正文的底部显示我的公司名称
作为超链接,就像这里:
www.mycompanyname.com ,所以这个人可以点击它并进入我的网站。
这应该是一个简单的任务,我从来没有做过以前这个。

彼得

"乔治" < ------@----.---& GT;在消息中写道
新闻:zB ******************* @ bgtnsc05-news.ops.worldnet.att.net ...

不确定这是否是您正在寻找的,但这是我的构建和


发送电子邮件。也许它会给你一些想法。

Private Sub sendMail(ByVal msgTxt As String)
Dim msg As MailMessage = New MailMessage()
SmtpMail.SmtpServer =" xxxx。 xxxx.com"
msg.Body = msgTxt
msg.From =" xx ** @ xxxxx.com"
msg.To =" xx ** @ xxxx.net"
msg.Subject =" Some Subject!"

尝试
SmtpMail.Send(msg)
Catch
结束尝试
End Sub

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

如果Not Request.UserAgent什么都没有那么
userAgent = Request.UserAgent
其他
userAgent ="没有用户代理可用!"
结束如果

''这就是我获取字符串的URL的方法
如果Not Request.UrlReferrer什么都没有那么
referPage = Request.UrlReferrer.ToString()
其他
referPage ="通过书签直接访问,基于本地的电子邮件


链接等。

结束如果

Dim msgTxt As String = vbCrLf& _
浏览器名称: &安培; Request.Browser.Browser& vbCrLf& _
浏览器类型: &安培; Request.Browser.Type& vbCrLf& _
浏览器版本: &安培; Request.Browser.Version& vbCrLf& _
浏览器平台: &安培; Request.Browser.Platform& vbCrLf& _
接受Cookies: &安培; Request.Browser.Cookies& vbCrLf& _
用户代理: &安培; userAgent& vbCrLf& _
用户主机地址: &安培; Request.UserHostAddress.ToString& vbCrLf&


_

"用户主机名:" &安培; Request.UserHostName& vbCrLf& _
引用网址: &安培; referPage

如果Not Request.Cookies(" userInfo")什么都没有那么
msgTxt = msgTxt& vbCrLf& vbCrLf& _
此次访问: &安培; Request.Cookies(" userInfo")(" thisVisit")


& vbCrLf& _

" Last Visit:" &


Request.Cookies(" userInfo")(" lastVisit")& vbCrLf& _

" Total Visits:" &


Request.Cookies(" userInfo")(" numVisits")& vbCrLf

结束如果

sendMail(msgTxt)
结束子

我使用Try \Catch \ End尝试邮件服务器关闭的情况。如果它


,我只是传递

那条特定的消息,因为我可以没有它。所以我不是真的


需要捕获该错误,我

只是不希望我的应用程序崩溃。用户代理和URL Referrer也会崩溃我的


应用程序,这就是为什么

我先检查它们。也许其他一些人也会,但不确定。

希望有所帮助。我只是在学习这些东西,所以有


可能是一个更好的方法。

我在这个NG中得到了很多答案,所以以为我会试着回馈一下


。 ; - )


George

Peter Afonin < pv*@speakeasy.net>在消息中写道


新闻:eV ************** @ TK2MSFTNGP10.phx.gbl ...

您好,

我创建了一个电子邮件表单,几乎与本文中描述的一样:
http://www.4guysfromrolla.com/webtech/080801-1.shtml 。它工作得很好,但我无法弄清楚一件事:

我需要在邮件正文的底部插入一个URL。我该怎么办呢?如果我只插入HTML - 它会显示HTML。我尝试了Response.Write
方法,StringBuilder和HTMLTextWriter类 - 到目前为止没有运气。

我很感激你对此的建议。

谢谢你,

-
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,

--
Peter Afonin

解决方案

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 = "xx**@xxxxx.com"
msg.To = "xx**@xxxx.net"
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

"Peter Afonin" <pv*@speakeasy.net> wrote in message news:eV**************@TK2MSFTNGP10.phx.gbl...

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,

--
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" <------@----.---> wrote in message
news:zB*******************@bgtnsc05-news.ops.worldnet.att.net...

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 = "xx**@xxxxx.com"
msg.To = "xx**@xxxx.net"
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

"Peter Afonin" <pv*@speakeasy.net> wrote in message


news:eV**************@TK2MSFTNGP10.phx.gbl...

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,

--
Peter Afonin




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" <pv*@speakeasy.net> wrote in message news:Ow**************@TK2MSFTNGP10.phx.gbl...

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" <------@----.---> wrote in message
news:zB*******************@bgtnsc05-news.ops.worldnet.att.net...

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 = "xx**@xxxxx.com"
msg.To = "xx**@xxxx.net"
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

"Peter Afonin" <pv*@speakeasy.net> wrote in message


news:eV**************@TK2MSFTNGP10.phx.gbl...

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,

--
Peter Afonin






这篇关于如何在ASP.Net电子邮件中插入URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆