The absolutely easiest and fastest way to send email...
This one line of code will create and send an e-mail message.
It uses the
FreeSMTP.Net assembly, which can be
downloaded here.
More on
FreeSMTP.Net in a minute...
VB Sample
Quiksoft.FreeSMTP.SMTP.QuickSend( _
"mail.yourdomain.com", _
"recipient@domain.com", _
"sender@domain.com", _
"Subject...", _
"Message text.", _
Quiksoft.FreeSMTP.BodyPartFormat.Plain)
C# Sample
Quiksoft.FreeSMTP.SMTP.QuickSend(
"mail.yourdomain.com",
"recipient@domain.com",
"sender@domain.com",
"Subject...",
"Message text.",
Quiksoft.FreeSMTP.BodyPartFormat.Plain);
It doesn't get much easier than this. Add a reference to
the
FreeSMTP.Net assembly, and call the QuickSend method.
Because the QuickSend() method is static, you do not even have to
instantiate a class. The method will even allow the sending
of HTML messages, by setting the last parameter to
BodyPartFormat.HTML.
FreeSMTP.Net is free as its name implies. But don't think
that because it is free, that it is not good.
FreeSMTP.Net
is produced by
Quiksoft who also produces the popular
EasyMail
Objects,
EasyMail Advanced API and
EasyMail .Net Edition.
Quiksoft specializes in e-mail technologies for professional
developers.
FreeSMTP.Net is offered by
Quiksoft as an
introduction to its product line. It is not often that you
find quality in things for free, but
FreeSMTP.Net is clearly an
exception.
Sending an attachment...
Since the QuickSend() method does not support attachments, we
will instantiate the
FreeSMTP.Net EmailMessage object, add the
attachments and send it with an instance of the
FreeSMTP.Net SMTP
class. As you can see, all this requires only a few lines of
code.
VB Sample
Dim msg As New EmailMessage( _
"recipient@domain.com", _
"sender@domain.com", "Subject...", _
"Message text.", _
BodyPartFormat.Plain)
msg.Attachments.Add("c:\\attachment.txt")
Dim smtp As New SMTP("mail.yourdomain.com")
smtp.Send(msg)
C# Sample
EmailMessage msg = new EmailMessage(
"recipient@domain.com",
"sender@domain.com", "Subject...",
"Message text.",
BodyPartFormat.Plain);
msg.Attachments.Add("c:\\attachment.txt");
SMTP smtp = new SMTP("mail.yourdomain.com");
smtp.Send(msg);
Sending HTML message with support for non HTML mail
readers...
To send an HTML message with support for non HTML mail readers,
we must actually send two message bodies. One is formatted
in HTML and the other in plain text. Mostly every non HTML
mail reader will be able to ignore the HTML and display the text
body instead.
Many people are using the System.Web.Mail class to send mail
through their .Net apps, but there are many reasons why this might
not be the best route. We will touch on this again, but for
now I would like to point out that the System.Web.Mail class does
not support sending more than one body format in the same message.
Therefore, the System.Web.Mail classes do not allow you to send
an HTML message with support for non HTML readers.
VB Sample
Dim msg As New EmailMessage( _
"recipient@domain.com", _
"sender@domain.com", "Subject...", _
"Text message.", BodyPartFormat.Plain)
Dim html As New String( _
"<html><body><b>HTML</b> message.</body></html>")
msg.BodyParts.Add(html, BodyPartFormat.HTML)
Dim smtp As New SMTP("mail.yourdomain.com")
smtp.LogFile = "c:\\smtp log.txt"
smtp.Send(msg)
C# Sample
EmailMessage msg = new EmailMessage(
"recipient@domain.com",
"sender@domain.com", "Subject...",
"Text message.", BodyPartFormat.Plain);
string html =
"<html><body><b>HTML</b> message.</body></html>";
msg.BodyParts.Add(html, BodyPartFormat.HTML);
SMTP smtp = new SMTP("mail.yourdomain.com");
smtp.LogFile="c:\\smtp log.txt";
smtp.Send(msg);
In this example we instantiate an EmailMessage class using the
overloaded constructor to create a plain text message. Next
we add a new body part to the message formatted as HTML. The
FreeSMTP.Net assembly will automatically use this information to
create a message that contains both plain text and HTML versions
of the message. Beneath the hood, the Send() method builds a MultiPart Alternative MIME message. The developer is
shielded from the complexity of MIME, but can rest assured that
their message is compatible with mostly every mail reader.
Continue on to find out about the #1 problem that affects most
developers sending e-mail from their apps...
Page Navigator:
<< Back,
1,
2,
3,
4,
Next >>
|
 |
|