I am using Visual Studio 2008 Express with C#. I have been trying to get an email routine to work in the code-behind on an aspx page.
All the MSDN examples, even those stated to be for .Net 3.5, do not compile. The MailMessage class has apparently changed a few times. Here is code that does compile, but this line of code, SmtpMail.Send(msg), has an error message that is vague:
"The best overloaded method match for 'System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMessage)' has some invalid arguements.
Can anyone see what the invalid arguements could be? This is all that is preventing this from working.
using System.Net;
using System.Net.Mail;
MailMessage msg = new MailMessage();
msg.ToAddress = new MailAddress("[email protected]");
msg.FromAddress = ("[email protected]");
msg.CCAddress = ("[email protected]");
msg.EmailMessage = "Order message test";
msg.EmailSubject = "Order Confirmation";
msg.MailEncoding = "html";
msg.MailPriority = MailPriority.Normal.ToString();
SmtpClient SmtpMail = new SmtpClient();
SmtpMail.Host = "smtpout.secureserver.net";
SmtpMail.Port = 25;
try
{
SmtpMail.Send(msg); // This is where the error occurs.
}
catch (Exception ex)
{
// Incomplete here
}