Hi Devs,
The following is the piece of code to send Email from webpart.
menggunakan Sistem;
menggunakan System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.ObjectModel;
using Microsoft.SharePoint.Utilities;
menggunakan Microsoft.SharePoint;
using System.Data;
using System.Collections;
namespace SendMail
{
public class SendMail : Microsoft.SharePoint.WebPartPages.WebPart
{
private TextBox txtTo;
private Button btnSendMail;
protected override void CreateChildControls()
{
txtTo = new TextBox();
this.Controls.Add(txtTo);
btnSendMail = new Button();
btnSendMail.Text = “Send Email”;
btnSendMail.Click = new EventHandler(SendMail_Click);
this.Controls.Add(btnSendMail);
}
void SendMail_Click(object sender, EventArgs e)
{
SPSite _site = new SPSite(HttpContext.Current.Request.Url.ToString());
SPWeb _web = _site.OpenWeb();
_web.AllowUnsafeUpdates = true;
SPUtility.SendEmail(_web, palsu, palsu, txtTo.Text, “Test Email”, “Text Body Message”);
_web.Dispose();
_site.Dispose();
}
}
}
Create the WebPart and register it as SafeControl
Tinggalkan Reply