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);
}