Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send an inserted html e-mail by SmtpMail 1

Status
Not open for further replies.

lunargirrl

Programmer
Jan 26, 2004
77
BR
Hi :)
I am using asp.net to send an inserted html e-mail by SmtpMail.

I use: Email.aspx - is my html page which contains some dynamic fields such as user id, username (everything included in the body of this page.


Main page:

...
Context.Items.Add("ID", dsSearch.Tables(0).Rows(0).Item(0))
Context.Items.Add("UserName", dstPesquisa.Tables(0).Rows(0).Item(1))

Dim objResponse As WebResponse
Dim objRequest As WebRequest=System.Net.HttpWebRequest.Create("Email.aspx")
objResponse = objRequest.GetResponse
Dim sr As New StreamReader(objResponse.GetResponseStream)
Dim strMessage As String = sr.ReadToEnd()

objMail.From = "me@myself.com"
objMail.To = "you@yourself.com"
objMail.Subject = "This is a test"
objMail.Body = strMessage
objMail.BodyFormat = MailFormat.Html


Try
SmtpMail.SmtpServer = "10.0.0.1"
SmtpMail.Send(objMail)
Catch err As Exception
Response.Write(SmtpMail.SmtpServer + err.Message)
End Try

Problems I found:

1) the sintax WebRequest=System.Net.HttpWebRequest.Create("Email.aspx") gives me the error "Invalid URI"

2) How can I bound the fields of Email.aspx to the variables (id, username) that I have in my main page?

Please someone could help me??
I tried, tried many times and had no sucess.

TIA,
Gisele
 
Here is the code that I use to send an email. Hope this helps.

Imports System.Web.Mail


Inside of a Sub...

Try
Dim myMessage As New MailMessage
myMessage.From = Session("gstrUserID") & "@MyDomain.com"
myMessage.To = Session("gstrMgrEmail")
myMessage.Subject = Session("gstrUserID") & " has updated a record."
myMessage.Body = Session("gstrUserID") & " has changed a record. Please check to see if anything is needed. THANK YOU!"

SmtpMail.SmtpServer = "SMTPServerName"
SmtpMail.Send(myMessage)
Catch ex As Exception
lblError.Text = "Email didn't get sent. " & ex.Message
End Try


Hope everyone is having a great day!

Thanks - Jennifer
 
Hi Gisele

1) You need to provide the fully qualified URI to the Create mehtod like this.
Code:
Dim objRequest As WebRequest=System.Net.HttpWebRequest.Create("[URL unfurl="true"]http://mydomain.com/Email.aspx")[/URL]
Replace mydomain.com with the domain of your website e.g. or localhost if you are developing and testing on the same machine.

2) You can pass the username and password to Email.aspx in the querystring like this
Code:
Dim objRequest As WebRequest=System.Net.HttpWebRequest.Create("[URL unfurl="true"]http://mydomain.com/Email.aspx?id="[/URL] & id & "&username=" & username)
You can then retrieve these in Email.aspx using
Code:
Dim id As String = Request.Querystring("id")
Dim username As String = Request.Querystring("username")

Sorry for any syntax errors in my VB, I am a C# guy these days.

HTH

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
thanks jennufer but I am having a problem to send an html page (or e-mail) by mail...
:)
 
Hopefully Rob was more help. :)

Hope everyone is having a great day!

Thanks - Jennifer
 
Rob, thanks a lot
A question: is it secure to send the password in this way???

gisele
 
Not really as the request could be intercepted and the password compromised. However, as the Email.aspx is never displayed in the browser it isn't so bad. If this is all internal on a corporate network then it is less of a problem.

If you want to be certain you can encrypt the password before adding to the querystring and decrypt it in Email.aspx. Here is a good article on doing this in ASP.NET from 4guysfromrolla


Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
Thanks Rob, Now i am going to check the encrypt article.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top