Hi,
You NEED an SMTP server to send email regardless of the
programming/scripting language. The Send Mail Transport Protocol is the
standard used for sending email across the internet.
For .NET, most hosts (if your doing web applications) have that already
installed, but if your doing a normal application, then you have an SMTP server to send the email. Usually, programmers supply an option
in the program so the user can change the SMTP information so that the
program could work. I usually allow the user add his email SMTP
information into the settings of the program so that he/she could use
the email features.
You can send e-mails without SMTP. For more info look at this http://www.eggheadcafe.com/articles/20030316.asp
You can use algorithm of DNS lookup in ANSMTP which enables your application
to send email without SMTP server.
Installation and Deployment
You should download the ansmtp installer
and install it on your machine at first.
How does it work?
In general, we send email via specified SMTP server. How does the specified
SMTP server know what address this email should be sent to? It queries MX
record of recipient's domain via DNS lookup. Then it forwards this email to the
SMTP server queried from DNS server. If the recipient's server doesn't work
fine, your SMTP server will send an email to tell the sender there is failure
in sending this email.
How does ANSMTP work with DNS lookup? ANSMTP queries DNS directly from DNS,
then send email to recipient's email server. If it fail, SendMail method will
fail in synchronous mode and OnError event will occur (instead of sending an
email to tell sender) in asynchronous mode, and your application can do
something for this failure. If it fail in sending email via DNS lookup, it will
also fail in sending email with specified SMTP server.
Send email without specified SMTP server
We just need to assign "" to ServerAddr property of ANSMTP, ANSMTP would send
email via automatically.
C# Example private void SendEmail() { AOSMTPLib.MailClass oSmtp = new AOSMTPLib.MailClass(); //If you don't have a SMTP server, use the following code //send email via DNS lookup, ANSMTP lookups SMTP server automatically. oSmtp.ServerAddr = ""; oSmtp.FromAddr = "test@adminsystem.net"; oSmtp.AddRecipient( "Support Team", "support@adminsystem.net", 0 );
oSmtp.Subject = "Test"; oSmtp.BodyText = "Hello, this is a test...."; if( oSmtp.SendMail() == 0 ) Console.WriteLine( "Message delivered!" ); else Console.WriteLine( oSmtp.GetLastErrDescription()); }
Limitations with DNS lookup
If you specified multiple recipients, make sure all recipients' email
addresses belong to the same domain, otherwise "Error with sending recipient"
occurs.
C# Example private void SendEmail() { AOSMTPLib.MailClass oSmtp = new AOSMTPLib.MailClass(); //If you don't have a SMTP server, use the following code //send email via DNS lookup, ANSMTP lookups SMTP server automatically. oSmtp.ServerAddr = ""; oSmtp.FromAddr = "test@emailarchitect.net"; //Correct, both support@adminsystem.net and test@adminsystem.net //belong to adminsystem.net oSmtp.AddRecipient( "Support Team", "support@adminsystem.net", 0 ); oSmtp.AddRecipient( "Tester", "test@adminsystem.net", 1 ); oSmtp.Subject = "Test"; oSmtp.BodyText = "Hello, this is a test...."; if( oSmtp.SendMail() == 0 ) Console.WriteLine( "Message delivered!" ); else Console.WriteLine( oSmtp.GetLastErrDescription()); }
The code below shows how to send email to multiple recipients who don't belong
to the same domain.
C# Example private void SendEmail() { AOSMTPLib.MailClass oSmtp = new AOSMTPLib.MailClass(); oSmtp.FromAddr = "test@emailarchitect.net"; oSmtp.Subject = "Test"; oSmtp.BodyText = "Hello, this is a test...."; string[] recipients = new string[2]; recipients[0] = "support@adminsystem.net"; recipients[1] = "test@hotmail.com"; for( int i = 0; i < recipients.Length; i++ ) { oSmtp.ClearRecipient(); oSmtp.AddRecipient( recipients[i], recipients[i], 0 ); oSmtp.ServerAddr = ""; if( oSmtp.SendMail() == 0 ) Console.WriteLine( "Message to {0} delivered!", recipients[i] ); else Console.WriteLine( "Message to {0} failed: {1}", recipients[i], oSmtp.GetLastErrDescription()); } }
|