Sending email

  • Thread starter Thread starter John S
  • Start date Start date
J

John S

I have applied this code
myMessage.To=MessageTo;
myMessage.From=MessageFrom;
myMessage.Subject=Subject;
myMessage.Body=Body;
myMessage.Priority=MailPriority.High;
SmtpMail.SmtpServer=SMTPServer;

but I keep getting back the error message
"Could not access "CDO.Message" object.
What am I missing? Did I forget to set something up?
 
Hello,

To simply answer this, you need to run this command after your existing
code:
SmtpMail.Send(myMessage);

You might also make sure you created a Message object since it is not
static.
MailMessage myMessage = new MailMessage();

However, you may run into many difficulties depending on how you setup the
object. I've found that if there are any errors at all, it gives you a very
vague error message. I think it's something like "Cannot Access object "
CDONTS.blah blah.

Here's a few things to keep in mind:
--- Even though the MSDN docs say you can send to multiple recipients by
delimiting the addresses with a semicolon, this doesn't work. It seems to
only work when you send the MailMessage with ONE recipient at a time. So the
solution to that is to setup the MailMessage object with the common
from,body,subject, etc fields, and then create a loop for the recipients and
send the MailMessage object individually.

--- The mail server you're using should allow it to send the message. By
default SmtpMail.SmtpServer is localhost. This should work fine if you have
the default SMTP virtual server installed with IIS. If you use an external
server, make sure the machine running the code has relay privileges.

Here's sample using your code.

-----------------------------
using System.Web.Mail;

//...class declaration

void sendMail()
{
MailMessage myMessage = new MailMessage();
myMessage.To = "(e-mail address removed)";
myMessage.From = "(e-mail address removed)";
myMessage.Subject = "subject";
myMessage.Body = "body";
myMessage.Priority = MailPriority.High;
SmtpMail.SmtpServer = "smtp_server"; //this line is optional
SmtpMail.Send(myMessage);
}
 
Actually, here's the whole routine I use for simple email

Dim objMail

Set objMail=CreateObject("CDO.Message")
objMail.Subject=Subject
objMail.From=MessageFrom
objMail.Sender=MessageFrom
objMail.To=MessageTo
objMail.TextBody="This is a message."
objMail.Send

Set objMail = Nothing


Regards,

Debbie Gimbal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top