SENDING E-mails using asp.netby faISAL khan.
Of Both Text and Html Formats Using Classes of System.Web.mail Namespace. Web.mail Namespace, Overviewin this Tutorial WE WILL LEARN HOW.
BEFORE DELVING in To The Source Code, I'll Briefly Explain The MailMessage and SMTPMAIL CLASESS Which We'll BE Using to Send E-MAILS.
System.Web.mail.mailmessagean Object of this class represents a single e-mail message. Properties of this class area listed Below:
Properties of MailMessage
To Use this class, we create a new object, set some of it's profib. ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
MailMessage Mail = New MailMessage ();
Mail.to = "Receivers@emil.address";
Mail.from = "senders@emil.address";
Mail.BodyFormat = mailformat.text;
Mail.subject = "Subject of this email";
Mail.Body = "Body of this message."
SMTPMAIL.SEND (MAIL);
All the code required to create and send a MailMessage object has been shown above. If you've understood this code then you do not need to go any further. Just change the values to suite your needs. In the rest of this article we Will Create a Sendmail.aspx Page Which Will Make Use of the Above Code.
High-End Commercial Email Component: i. Aspemail: MOST Feature-Rich Mailing Component. Supports message Queueing, Embedded Images, Secure Mail, Authentication. Read more.
System.Web.Mail.SmtpMailThis class is used to * send * e-mails (MailMessages) using SMTP protocol. All we are interested as far as this tutorial is concerned are the two static methods (Send ()) it provides. You just Use the static method, provide a valid mailmessage object as the argument, and send it! .properties and methods of smtpmail
Sendmail.aspxit is Time Now That We create A Simple ASNET Page Which provides a form to you, you enter the value: a confirmation message is the message. a confirmation message is the meaninged.
Create a new .aspx page and save it as sendmail.aspx in a folder accessible by your server. Now copy and paste the folload code in it:
<% @ Page language = "c #"%>
<% @ Import namespace = "system.web.mail"%>
Protected Void Page_Load (Object Sender, Eventargs E) {
IF (! page.ispostback)
Message.text = "Sending E-mail Using ASP.NET";
}
Protected void send_email (Object sender, eventargs e) {
MailMessage Mail = New MailMessage ();
Mail.to = Request.form ["to"];
Mail.From = Request.form ["from"];
IF (Request.form ["Format"]. Equals ("text")))
Mail.BodyFormat = mailformat.text;
Else
Mail.BodyFormat = MailFormat.html;
Mail.subject = Request.form ["Subject"];
Mail.Body = Request.form ["Body"];
SMTPMAIL.SEND (MAIL);
Response.flush ();
Message.Text = "Message Sent ...
"
" Go back ";
}
script>
A {font-size: 8pt; font-family: tahoma; font-weight: Normal; Color: maroon;
style>
hEAD>
p>
<% IF (! page.ispostback) {%>
all fields are required. p>