create send mail application in sharepoint using custom code.input provide from using sharepoint custom webpart property.
01 | using System; |
02 | using System.Runtime.InteropServices; |
03 | using System.Web.UI; |
04 | using System.Web.UI.WebControls.WebParts; |
05 | using System.Xml.Serialization; |
06 | using Microsoft.SharePoint; |
07 | using Microsoft.SharePoint.WebControls; |
08 | using Microsoft.SharePoint.WebPartPages; |
09 | using System.Web.UI.WebControls; |
10 | using System.ComponentModel; |
11 | using System.Drawing; |
12 | using System.Collections.Generic; |
13 | using System.Data; |
14 | using Microsoft.SharePoint.Utilities; |
15 | using System.Web.UI.HtmlControls; |
16 | using System.Web.Mail; |
17 |
18 | namespace 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