The code sample is written in C# and intends to send mail from .NET applications. The code is implemented as a partial class in C# that extends a Page class. Thus making the code easily reusable.
The method that actually sends the e-mail is an event handler for a button. So, to use this code create a .aspx page with a button, textarea, and corresponding textboxes. Attach this handler to the button's click event.
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Mail;
public partial class SendingMail : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSend_Click(object sender, EventArgs e) { // Sending mail using Code.. MailMessage mm = new MailMessage(); try { mm.From = "gagrawal@del.aithent.com"; mm.To = txtTO.Text.ToString(); mm.Cc = txtCC.Text.ToString(); mm.Bcc = txtBCC.Text.ToString(); mm.Body = txtBody.Text.ToString(); mm.Subject = txtSubject.Text.ToString(); string filePath = fileupload1.PostedFile.FileName; mm.Attachments.Add(new System.Web.Mail.MailAttachment(filePath,MailEncoding.UUEncode)); System.Web.Mail.SmtpMail.Send(mm); lblMessage.Text = "Email successfully sent."; } catch(Exception ex) { lblMessage.Text = "Send Email Failed." + ex.Message; } } }
|
| Author: Junaid Soomro 09 Nov 2008 | Member Level: Bronze Points : 0 |
Please Create "aspx" file and send complete in zip. Thanks.
|