catalyst2 community forums  

Go Back   catalyst2 community forums > Support > Scripting Support

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 04-07-2007, 03:37 PM   #1 (permalink)
Registered User
 
WillR's Avatar
 
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
WillR is offline   Reply With Quote
Old 04-07-2007, 04:15 PM   #2 (permalink)
Bring me your problems :p
 
paulredpath's Avatar
 
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
paulredpath is offline   Reply With Quote
Old 05-07-2007, 12:53 PM   #3 (permalink)
Registered User
 
WillR's Avatar
 
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
WillR is offline   Reply With Quote
Old 05-07-2007, 02:48 PM   #4 (permalink)
Administrator
 
WhiskyFudge's Avatar
 
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
WhiskyFudge is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:36 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.