Γεια Devs,
The following is the piece of code to send Email from webpart.
using System;
using 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;
using 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 ε)
{
SPSite _site = new SPSite(HttpContext.Current.Request.Url.ToString());
SPWeb _web = _site.OpenWeb();
_web.AllowUnsafeUpdates = true;
SPUtility.SendEmail(_web, ψευδής, ψευδής, txtTo.Text, “Test Email”, “Text Body Message”);
_web.Dispose();
_site.Dispose();
}
}
}
Create the WebPart and register it as SafeControl
Αφήστε μια απάντηση