Monday, November 05, 2007

How to enable SMTP Authentication using System.Web.Mail

인증을 필요로 하는 SMTP서버를 사용하기 위해서는 코드 수정을 필요로 합니다.

SUMMARY
This article describes how to send e-mails from a .NET application through an SMTP server that requires authentication.
Back to the top

SYMPTOMS
Exchange Server requires, by default, authenticated users to send mail messages via SMTP. If you are developing a .NET application you will find that System.Web.Mail does not contain an API that allows you to provide credentials for connecting to an SMTP server. System.Web.Mail internally calls Microsoft® Collaboration Data Objects CDOSYS. SMTP Authentication is possible by defining configuration settings using the Configuration object associated to the Message CDO object.


Back to the top

MORE INFORMATION
The System.Web.Mail namespace provides an API that enables you to create and send messages using the CDOSYS (Collaboration Data Objects for Windows 2000) message component. The mail message is delivered through an SMTP server.
Most of the SMTP servers installations requires authentication. The main reasoning for this is due to people abusing SMTP servers for SPAMing (i.e., sending out unsolicited junk mail).
The System.Web.Mail namespace classes don't expose an API for providing credentials to an SMPT server. Anyway you can achieve this by defining configuration settings for the Configuration object associated to the Message CDO. Configuration settings are made up of a set of fields (properties) that are simply name/value pairs. Most configuration fields used for messaging are in the http://schemas.microsoft.com/cdo/configuration/ namespace.
You can set fields to the message by adding them to the System.Web.Mail.MailMesage.Fields collection.

CDO Fields for configuring SMTP Authentication
To configure Message objects, you modify fields in the associated Configuration object. Most of the field names reside in the http://schemas.microsoft.com/cdo/configuration/ namespace:
• smtpserver: SMTP server name.
• smtpserverport: SMTP server port (default: 25).
• sendusing: cdoSendUsingPort, value 2, for sending the message using the network.
• smtpauthenticate: Specifies the mechanism used when authenticating to an SMTP service over the network. Possible values are:
- cdoAnonymous, value 0. Do not authenticate.
- cdoBasic, value 1. Use basic clear-text authentication. When using this option you have to provide the user name and password through the sendusername and sendpassword fields.
- cdoNTLM, value 2. The current process security context is used to authenticate with the service.
• sendusername: User name
• sendpassword: Password

No comments: