Monday, March 26, 2012

System.Net.Mail class smtpdemo needs users address in message body from txt.emailAddress

I have this code behind from the new asp.net 2.0 System.Net.Mail class smtpdemo i am working with. It sends an HTML email to myself the from address and to the email address in txt.emailAddress as a CC. I am trying to get the txt.email address somewhere in the message body that it sends out. this code does not show the imputed contents of txt.emailaddress anywhere in the email so i canot reply to the sender. It declaires me as the sender and sends the person filing out the form an email. I need to declar the contents of txt.emailadress as a variable and call it in the message body. Ive tryed dozens of different ways but they all have errors. i hope someone can look at this code and show me how to get the users email address sent with the message.
/code/
Imports System.Net.Mail

PartialClass report_aspx

Inherits System.Web.UI.Page

ProtectedSub sendEmail_Click(ByVal senderAsObject,ByVal e _

As System.EventArgs)Handles sendEmail.Click

Dim sBodyAsString

Dim fileReaderBodyAsString

Dim fileReaderFormatAsString

Dim WebDirectoryAsString = Server.MapPath(".") &"\"

Dim fileNameAsString = WebDirectory

Dim htmlEmailFormatAsString = WebDirectory &"MailFormat.htm"

SelectCase Subject.Text

Case"Broken Link"

fileName = fileName &"BrokenLink.txt"

Case"Missing Picture"

fileName = fileName &"MissingPicture.txt"

Case"Typographical Error"

fileName = fileName &"TypoError.txt"

CaseElse

fileName = fileName &"other.txt"

EndSelect

fileReaderBody =My.Computer.FileSystem.ReadAllText(fileName)

fileReaderFormat =My.Computer.FileSystem.ReadAllText(htmlEmailFormat)

sBody = fileReaderFormat.Replace("BODYGOESHERE", _

messageBody.Text)

sBody = sBody.Replace("CONTENTGOESHERE", fileReaderBody)

sBody = sBody.Replace("SUBJECTGOESHERE", Subject.Text)

Dim toAddressAs MailAddress =New _

MailAddress(me@dotnet.itags.org.myemailaddress,"Webmaster")

Dim ccAddressAs MailAddress =New _

MailAddress(emailAddress.Text, emailName.Text)

Dim SenderAddressAs MailAddress =New _

MailAddress(emailAddress.Text)

Dim fromAddressAs MailAddress =New _

MailAddress(me@dotnet.itags.org.myemailaddress)

Dim eMailAs MailMessage =New _

MailMessage(fromAddress, fromAddress)

eMail.CC.Add(fromAddress)

eMail.Subject = Subject.Text

Dim htmlTypeAs System.Net.Mime.ContentType = _

New System.Net.Mime.ContentType("text/html")

Dim txtTypeAs System.Net.Mime.ContentType = _

New System.Net.Mime.ContentType("text/plain")

eMail.AlternateViews.Add( _

AlternateView.CreateAlternateViewFromString(sBody, htmlType))

eMail.AlternateViews.Add( _

AlternateView.CreateAlternateViewFromString(fileReaderBody & vbCrLf & messageBody.Text, htmlType))

Dim attchmentAs Attachment =New _

Attachment(WebDirectory &"goldbar.gif")

eMail.Attachments.Add(attchment)

Dim clientAs SmtpClient =New SmtpClient("myemailserver")

client.Send(eMail)

lblMessageSent.Text ="MESSAGE SENT"

emailAddress.Text =""

emailName.Text =""

messageBody.Text =""

EndSub

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

EndSub

EndClass
/end code/

I fixed my form by modifying the mailformat.htm page that I will place below and adding:

/codebehind file/
Body = sBody.Replace("NAMEGOESHERE", emailName.Text)

sBody = sBody.Replace("EMAILFROMGOESHERE", emailAddress.Text)
/end codebehind file/
/mailformat.html/

<html><body><h1>SUBJECTGOESHERE</h1><imgsrc="goldbar.gif"/><br/>BODYGOESHERE

<br/>

<imgsrc="goldbar.gif"/><br/>

NAMEGOESHERE<br/>

EMAILFROMGOESHERE<br/>

<br/>

<blockquote>CONTENTGOESHERE</blockquote></body></html>

0 comments:

Post a Comment