If your server requires you to authenticate with a user name
and password...
If your server will allow you to authenticate with a user name
and password, you can configure your application to do so.
We have been using the
FreeSMTP.Net classes thus far, however one
feature it does not support is SMTP authentication with a user
name and password. For the following example we will use the
SMTP class of
EasyMail .Net Edition to do the authentication.
EasyMail .Net Edition is the big brother to
FreeSMTP.Net. It
can be
downloaded here. The interface is the same as
FreeSMTP.Net and is therefore compatible with it. So if you
develop your application with
FreeSMTP.Net and then want to add
more power or features later, upgrading to
EasyMail .Net Edition
is a snap. Here is the code, using
EasyMail .Net Edition
which does the authentication:
VB Sample
Quiksoft.EasyMail.SMTP.License.Key = _
"Put your license key here"
Dim msg As New EmailMessage( _
"recipient@domain.com", _
"sender@domain.com", "Subject...", _
"Message text.", BodyPartFormat.Plain)
Dim smtp As New SMTP()
Dim server As New SMTPServer()
server.Name = "mail.yourdomain.com"
server.AuthMode = SMTPAuthMode.AuthLogin
server.Account = "user"
server.Password = "password"
SMTP.SMTPServers.Add(server)
smtp.Send(msg)
C# Sample
Quiksoft.EasyMail.SMTP.License.Key=
"Put your license key here";
EmailMessage msg = new EmailMessage(
"recipient@domain.com",
"sender@domain.com", "Subject...",
"Message text.", BodyPartFormat.Plain);
SMTP smtp = new SMTP();
SMTPServer server = new SMTPServer();
server.Name="mail.yourdomain.com";
server.AuthMode=SMTPAuthMode.AuthLogin;
server.Account="user";
server.Password="password";
smtp.SMTPServers.Add(server);
smtp.Send(msg);
The code here is somewhat different to what we have seen in the
past. I want to note that the same code we previously wrote
for
FreeSMTP.Net will compile and run perfectly with the
EasyMail .Net Edition classes. But for this example, I wanted to
change the code a bit to show you some of the advanced
capabilities of
EasyMail .Net Edition.
The first difference you will notice is the assignment of a
LicenseKey property in the first line of code.
EasyMail .Net Edition requires a license key to operate. You can obtain a
trial license key or purchase a permanent one from
Quiksoft.
Another item to note is the creation of the SMTPServer object
which is added to the SMTPServers collection.
EasyMail .Net Edition enables you to specify an unlimited number of servers for
your outgoing message. This is for backup or failsafe
operations. Each server in the list is tried until the
message is sent successfully. Therefore if your primary mail
server is down, the message may still be delivered. In this
example however we have only specified one server. The AuthMode, Account and Password properties of the SMTPServer class
are used to setup the authentication.
EasyMail .Net Edition supports many more features than
FreeSMTP.Net or System.Web.Mail. You can
view a comparison
here.
Conclusion...
That's really it - it's pretty simple. Armed with the knowledge
I have supplied and the software such as
FreeSMTP.Net or
EasyMail .Net Edition
you will have your .Net applications sending world class e-mail in
no time. In a future edition I will tackle more advanced
SMTP topics such as mass mailings, dealing with international
character sets, tracking the delivery status of your messages,
importing HTML content and more... If you have suggestions
for newsletter material involving any other SMTP issue, please let
me know.
John Alessi has specialized in e-mail development for the past
6 years and has helped many large companies such as Microsoft, Boeing
and EarthLink with their e-mail needs. He can be reached at
john@quiksoftcorp.com.
Page Navigator:
<< Back,
1,
2,
3,
4
|
 |
|