.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

create send mail application in sharepoint using custom code.

Posted By:Sagar Pardeshi       Posted Date: February 10, 2011    Points: 10    Category: SharePoint    URL: http://www.dotnetspark.com  

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

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
     ToolboxData("<{0}:GridViewWebPart runat=server>"),
     XmlRoot(Namespace = "GridViewWebPart")]

    public class SendMail : Microsoft.SharePoint.WebPartPages.WebPart
        #region Variables Declation
        HtmlButton btnSendMail;

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

        private void btnSendMail_ServerClick(object sender, EventArgs e)
                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";
                Context.Response.Write("Mail Sent Successfully");
            catch (Exception ex)


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend