Should the SmtpMail class have a port property?
We are using the SmtpMail class to send email. There is a property named SmtpServer. Should there not also be a property to allow setting the port number? The default of 25 works ok, but in situations where a non-standard port number is used, the SmtpMail class will not support it. Using a non-standard port is a good means of increasing security so that viruses, worms, etc. will not be able to find a SMTP server to use just by scanning for port 25. Is there a reason this is not included as a property in the SmtpMail class? Will this be the same in version 2.0?
I did find how to make it work using the MailMessage class, however, this is not an intuitive way to set the server and port.
| |
message.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = server; message.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = serverport; message.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
|
[1249 byte] By [
minton] at [2008-1-13]
Hello,
I believe your code is correct for setting the port number in the current version of System.Web.Mail.
In v2.0, System.Web.Mail will be replaced with a new mail API in System.Net.Mail. In System.Net.Mail you send emails using the SmtpClient type. You can set the port on the SmtpClient using the constructor, the Port property, or through configuration.
| |
// These are all System.Net.Mail types, including MailMessage. MailMessage message = new MailMessage(from, to, subject, body); SmtpClient client = new SmtpClient(serverName, serverPort); client.Send(message);
|
Daniel Roth