create send mail application in sharepoint using custom code.input provide from using sharepoint custom webpart property

Sagarp
Posted by Sagarp under Others category on | Points: 40 | Views : 3652
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
using System.Collections.Generic;
using System.Data;
using Microsoft.SharePoint.Utilities;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

namespace GridViewWebPart
{
[DefaultProperty("Text"),
ToolboxData("<{0}:GridViewWebPart runat=server></{0}:GridViewWebPart>"),
XmlRoot(Namespace = "GridViewWebPart")]

public class SendMail : Microsoft.SharePoint.WebPartPages.WebPart
{
#region Variables Declation

HtmlButton btnSendMail;

#endregion

protected override void CreateChildControls()
{
base.CreateChildControls();
btnSendMail = new HtmlButton();
btnSendMail.InnerText = "Send Mail";
btnSendMail.ID = "SendMail";
btnSendMail.ServerClick += new EventHandler(btnSendMail_ServerClick);
Controls.Add(btnSendMail);
}

private void btnSendMail_ServerClick(object sender, EventArgs e)
{
try
{
MailMessage oMailMessage = new MailMessage();
oMailMessage.From = "martin@xyz.com";
oMailMessage.To = "jon@xyz.com";
oMailMessage.Cc = "pqr@xyz.com";
oMailMessage.Cc = "abc@xyz.com";
oMailMessage.Subject = "Test Mail";
oMailMessage.Body = "Test Mail";

//SmtpMail.SmtpServer = "localhost";
SmtpMail.SmtpServer = "mail.xyz.com";
SmtpMail.Send(oMailMessage);
Context.Response.Write("Mail Sent Successfully");
}
catch (Exception ex)
{
Context.Response.Write(ex.Message);
}
}

}
}

Comments or Responses

Login to post response