Great article on how to upload and crop images at Mikesdotnetting blog.
I was recently looking for a way to add an email to a user's draft folder with attachements. Exchange web services was the ticket. See the screen shot and code snippet attached.
The trick is to add to a user's outlook draft folder you need a user id with higher level rights and allow impersonation must be turned on in Exchange.
using System.DirectoryServices;
using Microsoft.Exchange.WebServices.Data;
namespace ExchangeWSTest
{
public partial class ActiveXTest : System.Web.UI.Page
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
protected void Page_Load(object sender, EventArgs e)
{
service.Credentials = new WebCredentials("youremail", "yourpassword");
service.Url = new Uri("https://client.yourexchangeserver.com/ews/exchange.asmx");
}
protected void BtnCreateMsg_Click(object sender, EventArgs e)
{
EmailMessage message = new EmailMessage(service);
message.Subject = TxtSubject.Text;
string MSG = TxtBody.Text;
MSG = MSG.Replace("\n", "
");
message.Body = MSG;
message.Attachments.AddFileAttachment(@"C:\temp\TEST Word Doc.docx");
message.Attachments.AddFileAttachment(@"C:\temp\TestPDF.pdf");
message.Save();
LblMsg.Text = "Email created, please check your draft folder";
}
}
}
//Class for generic list
public class MarketDates
{
public string DisplayDate { get; set; }
public string SelectDate { get; set; }
}
//List for binding
List LstFromDate = new List();
List LstToDate = new List();
//Load List
for (int i = 1999; i < (DateTime.Now.Year + 1); i++)
{
MarketDates DDLFromDate = new MarketDates();
MarketDates DDLToDate = new MarketDates();
DDLFromDate.DisplayDate = "JAN-" + i.ToString();
DDLFromDate.SelectDate = i.ToString();
LstFromDate.Add(DDLFromDate);
DDLToDate.DisplayDate = "DEC-" + i.ToString();
DDLToDate.SelectDate = i.ToString();
LstToDate.Add(DDLToDate);
}
//Bind
DDLFromYear.DataTextField = "DisplayDate";
DDLFromYear.DataValueField = "SelectDate";
DDLFromYear.DataSource = LstFromDate;
DDLFromYear.DataBind();
DDLToYear.DataTextField = "DisplayDate";
DDLToYear.DataValueField = "SelectDate";
DDLToYear.DataSource = LstToDate;
DDLToYear.DataBind();