Forum Moderators: open

Message Too Old, No Replies

How to us CDONTS in C#

         

IntegrityWebDev

2:04 pm on Mar 4, 2010 (gmt 0)

10+ Year Member



I am helping someone with GoDaddy Hosting (IIS6) and GoDaddy gave them the following code to use for sending email from a form.

<%
from = request.form("from")
body = request.form("body")
subject = request.form("subject")
%>

<%
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = from
objMail.Subject = subject
objMail.To = "hard-code your email address"
objMail.Body = body
objMail.Send

Set objMail = Nothing
Response.redirect "thankyou.asp"


But I need this code for C#.

I know there is another (better?) method for sending email that requires putting in username and password but the person I'm helping doesn't want to use that and wants to go with CDONTS.

Can anyone help with a simple CDONTS example in C#?

Thanks!
Chris

IntegrityWebDev

2:30 pm on Mar 4, 2010 (gmt 0)

10+ Year Member



It's one of those times (seems to happen to me from time to time) where I work on a problem for a couple of hours, then post here....then I find a solution!

This worked using System.Web.Mail:


MailMessage mail = new MailMessage();
mail.To = "you@your.com";
mail.From = "me@my.com";
mail.BodyFormat = MailFormat.Html;
mail.Subject = "Testing Email";
mail.Body = "LET ME KNOW IF YOU GET THIS";
SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
SmtpMail.Send( mail );


BTW, for anyone who may be searching for how to send email through a form with C#, if you using GoDaddy Hosting and IIS6 the server listed is the actual server GoDaddy said to use and the end user did get the email.

Thanks!
Chris

marcel

2:34 pm on Mar 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi IntegrityWebDev, here is a simple example

// Create the message object
MailMessage mail = new MailMessage();

// Add sender and receiver
mail.From = new MailAddress("sender@example.com");
mail.To.Add("receiver@example.com");

//Add the content
mail.Subject = "My Subject";
mail.Body = "Lorem ipsum dolor sit amet";

//Send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Credentials = new NetworkCredential("login", "password");
smtp.Send(mail);


Here is all the info you will ever need:
www.systemnetmail.com [systemnetmail.com]

marcel

2:36 pm on Mar 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This worked using System.Web.Mail:

You should use System.Net.Mail, the classes in the System.Web.Mail namespace have been deprecated
[msdn.microsoft.com...]

marcel

7:00 pm on Mar 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



oops, I read it wrong, I see now that you don't want to login with a username and password.

Just remove this line from the example I gave:
smtp.Credentials = new NetworkCredential("login", "password");