Saturday, March 24, 2012

HTML Email Help

I am trying to send an email automatically when a user has filled in a web form.

I have been using the contents of each textbox so that the email can display details of a specific order. For example, txtForename.text, which could contain "Jerry".

I have been trying many different ways to rectify the error, with now luck.

My code looks like this:

' Send Email to customer
Dim Mail As New MailMessage()
Mail.To = lblEmail.text
Mail.From = "rentals@dotnet.itags.org.OCR.com"
Mail.Subject = "Rental Details"
Mail.BodyFormat = MailFormat.Html
Mail.Body = "<h1>Rental Summary</h1><hr /><table width='100%'><tr><td colspan='2'><h2><u>Personal Details</u></h2></td></tr><tr><td></td><td></td></tr>" & _
"<tr><td width='9%'><b>Name:</b></td><td width='91%'>" & lblForename.text & lblSurname.text & "</td></tr><tr><td></td><td></td></tr><tr><td><b>Address:</b></td><td>"& lblAddress1.text &"</td>" & _
"</tr><tr><td></td><td>"& lblAddress2.text & "</td></tr><tr><td></td><td>" & lblCounty.text & "</td></tr><tr><td></td><td></td></tr><tr><td><b>Post Code:</b> </td><td>" & lblPostcode.text & "</td>" & _
"</tr><tr><td></td><td></td></tr><tr><td><b>Tel No:</b></td><td>" & lblTelNo.text & "</td></tr><tr><td></td><td></td></tr><tr><td><b>Email Address:</b> </td>" & _
"<td>" & lblEmail.text & "</td></tr><tr><td></td><td></td></tr></table><br /><table width='100%'><tr><td colspan='2'><h2><u>Purchase Information</u></h2></td>" & _
"</tr><tr><td width='10%'></td><td width='90%'></td></tr><tr><td><b>Car:</b></td><td>" & lblCarModel.text & "</td></tr><tr><td></td><td></td></tr><tr><td><b>Price:</b></td>" & _
"<td>" & lblCarPrice.text & "</td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr><tr><td><b>Accessory Name:</b></td><td>" & lblAccessoryName.text & "</td></tr><tr><td><b>Price:</b></td>" & _
"<td>" & lblAccessoryPrice.text & "</td></tr><tr><td></td><td></td></tr><tr><td><b>Pickup Date:</b></td><td>" & lblCollectDate.text & "</td></tr><tr><td></td><td></td></tr><tr><td><b>Return Date:</b></td>" & _
"<td>" & lblReturnDate.text & "</td></tr></table><br />"
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(Mail)

I have created the email in a table format as you can see. I don't think there is any errors in the email structure. However, I am getting the following error:

Server Error in '/' Application.

The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for someone@dotnet.itags.org.hotmail.com

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Runtime.InteropServices.COMException: The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for someone@dotnet.itags.org.hotmail.com

Source Error:

Line 153: "<td>" & lblReturnDate.text & "</td></tr></table><br />"
Line 154: SmtpMail.SmtpServer = "localhost"
Line 155: SmtpMail.Send(Mail)
Line 156:
Line 157: Response.Redirect("RecordProcess.aspx")


I would appreciate any help anyone could give me!

You need to pass username/pass to your SMTP or adjust the SMTP to allow your access.

There was a post yesterday with the exact syntax for passing the credentials, but basically that's all it is.


Thats great thanks for your help!

I will try it out!

No comments:

Post a Comment