Converting from system.web.mail to system.net.mail

I have been trying to convert to system.net.mail with no luck so far. I am positive that I have my smtp server ip, port and authentication correct. Here is a code example of how I am trying to send my emails using system.net.mail...

//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress(sendAddress);
mail.To.Add(recieveAddress);

//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";

//send the message
SmtpClient smtp = new SmtpClient(myIP);
smtp.EnableSsl = true;

smtp.Credentials = new NetworkCredential(username, password);

try
{
smtp.Send(mail);
reportBack.Text = "Your email has been sent successfully";
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}

Response.Write(errorMessage);
reportBack.Text = "Your email has NOT been sent successfully";
}


Here is a copy of the exception I recieve...

PostbackedSystem.Net.Mail.SmtpException: Command not implemented. The server response was: at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) at STAIRSdev.common.emailTest.btnSendEmailClick(Object sender, EventArgs e) in C:\Documents and Settings\Buff Bufferman\Desktop\STAIRSdev\STAIRSdev\common\emailTest.aspx.cs:line 93

Line 93 is the line smtp.Send(mail)

When I was using system.web.mail I was able to send email without authentication, here is how I sent my mail with web.mail

MailMessage msg = new MailMessage();
msg.To = recieveAddress;
msg.From = sendAddress;
msg.Subject = "Test";

msg.Body = "message body";

SmtpMail.SmtpServer = myIP;
SmtpMail.Send(msg);


Any thoughts


Answer this question

Converting from system.web.mail to system.net.mail

  • Blkbird

    I just tried commenting out EnableSsl = true; and it had no effect. The same exception is thrown.

  • Jackuline

    I will try and get a trace uploaded here...

  • Manoj Bhardwaj

    Is this mail server accessible from outside so we can test it If not can you get a netmon trace or a system.net trace and post it Without seeing what is going on the wire it is difficult to say where the problem is. One think you can try is to comment the credentials line a see if it will work with default credentials

    Mariya


  • YellowShadow

    I strongly suspect you did not use SSL with WebMail (using SSL is different from using credentials) - if this is the case then comment this line and it should work.

    smtp.EnableSsl = true

    Mariya


  • Converting from system.web.mail to system.net.mail