![]() |
|
|
#1 (permalink) |
|
Registered User
Join Date: Jun 2007
Posts: 10
|
Sending email with ASP .NET
Hi, I am trying to produce at a nice simple "contact us" form using the ASP .NET 2 namespace "System.Net.Mail" to send the mail. See C# code snippet below:
=============================== SmtpClient smtpClient = new SmtpClient(); MailMessage objMail = new MailMessage(); MailAddress objMail_fromaddress = new MailAddress(txtFrom.Text); MailAddress objMail_toaddress = new MailAddress(txtTo.Text); objMail.From = objMail_fromaddress; objMail.To.Add(objMail_toaddress); objMail.Subject = "Web Site Enquiry"; objMail.Body = "Name: " + txtName.Text + "\r\n" + "Address: " + txtAddress.Text + "\r\n" + "Message: " + txtComments.Text; objMail.Priority = MailPriority.Normal; smtpClient.Host = "mail.mydomain.co.uk"; smtpClient.Credentials = new System.Net.NetworkCredential("username@mydomain.co .uk","Password"); smtpClient.Send(objMail); etc... =============================== I have 2 questions: 1. Am I correct in setting the smtpClient Host property to "mail.mydomain.co.uk"? The site is going to be hosted on Cherry 2. Do I need to specify the smtp.Credentials property? I have sent a test email successfully without setting this property, so I'm a bit unsure about the security aspect here. I'd be grateful for advice from the experts. Cheers, Will |
|
|
|
|
|
#2 (permalink) |
|
Bring me your problems :p
Join Date: Jan 2003
Location: /dev/ahhhhhhhhh
Posts: 3,537
|
Will,
Please use the smtp server 'guava.catalyst2.com', you don't need any credentials and make sure that the from address on the email is @yourdomainhostedwithus. Everything should go smoothly then
|
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Jun 2007
Posts: 10
|
Paul, Thanks for the reply. My aim to allow a prospective customer to send an email to the site owner/sales person.
I include a text field on the Web form for the customer email address and then use this value as the email "From" address as below: MailAddress objMail_fromaddress = new MailAddress(txtFrom.Text); The enquiry email would need to go to a domain account, i.e. sales@mydomain.co.uk, so I hard-code this as below: MailAddress objMail_toaddress = new MailAddress("sales@mydomain.co.uk"); However, on your reply you mention that I need to "make sure that the from address on the email is @yourdomainhostedwithus". Is this correct? I thought this would be the customer's address, as above? Apologies if I'm being dim here... Thanks, Will |
|
|
|
|
|
#4 (permalink) |
|
Administrator
Join Date: Oct 2003
Posts: 1,484
|
Paul is mistaken, as long as one of the address's associated with the email is catalyst2 hosted the email can be sent using guava without the use of any credentials.
__________________
Jason Robbins jason@catalyst2.com |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|