create send mail application in sharepoint using custom code.


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



01using System;
02using System.Runtime.InteropServices;
03using System.Web.UI;
04using System.Web.UI.WebControls.WebParts;
05using System.Xml.Serialization;
06using Microsoft.SharePoint;
07using Microsoft.SharePoint.WebControls;
08using Microsoft.SharePoint.WebPartPages;
09using System.Web.UI.WebControls;
10using System.ComponentModel;
11using System.Drawing;
12using System.Collections.Generic;
13using System.Data;
14using Microsoft.SharePoint.Utilities;
15using System.Web.UI.HtmlControls;
16using System.Web.Mail;
17 
18namespace GridViewWebPart
19{
20    [DefaultProperty("Text"),
21     ToolboxData("<{0}:GridViewWebPart runat=server><!--{0}:GridViewWebPart-->"),
22     XmlRoot(Namespace = "GridViewWebPart")]
23 
24    public class SendMail : Microsoft.SharePoint.WebPartPages.WebPart
25    {
26        #region Variables Declation
27         
28        HtmlButton btnSendMail;
29         
30        #endregion
31 
32        protected override void CreateChildControls()
33        {
34            base.CreateChildControls();
35            btnSendMail = new HtmlButton();
36            btnSendMail.InnerText = "Send Mail";
37            btnSendMail.ID = "SendMail";
38            btnSendMail.ServerClick += new EventHandler(btnSendMail_ServerClick);
39            Controls.Add(btnSendMail);
40        }
41 
42        private void btnSendMail_ServerClick(object sender, EventArgs e)
43        {
44            try
45            {
46                MailMessage oMailMessage = new MailMessage();
47                oMailMessage.From = "martin@xyz.com";
48                oMailMessage.To = "jon@xyz.com";
49                oMailMessage.Cc = "pqr@xyz.com";
50                oMailMessage.Cc = "abc@xyz.com";
51                oMailMessage.Subject = "Test Mail";
52                oMailMessage.Body = "Test Mail";
53 
54                //SmtpMail.SmtpServer = "localhost";
55                SmtpMail.SmtpServer = "mail.xyz.com";
56                SmtpMail.Send(oMailMessage);
57                Context.Response.Write("Mail Sent Successfully");
58            }
59            catch (Exception ex)
60            {
61                Context.Response.Write(ex.Message);
62            }           
63        }
64         
65    }
66}

Comments