TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vidhi Patel
NA
44
17.6k
details of miscosoft exchane impliment in my application
Sep 12 2016 8:41 AM
http://www.c-sharpcorner.com/uploadfile/jj12345678910/readin this link you have menstion cridansials but in my application its not work .
i have selcted the part that is not workingin my application .
*>in form desing also
this.btnRead.Click += new System.EventHandler(this.btnRead_Click_1);
this is not working can you give me a vedio how to do this in details plez help me its argent
Microsoft Exchange Server
By Julian on
Aug 17, 2015
Form.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Exchange.WebServices.Data;
namespace WindowsFormsApplication1
{
public partial class Form1: Form
{
exchange =
new
ExchangeService(ExchangeVersion.Exchange2007_SP1);
exchange.Credentials =
new
WebCredentials(
"USERNAME"
,
"PASSWORD"
,
"DOMAIN"
);
//exchange.Credentials = new WebCredentials("julian", "mypassword", "mydomain");
exchange.AutodiscoverUrl(
"EMAILADDRESS"
);
//exchange.AutodiscoverUrl("
[email protected]
");
ExchangeService exchange = null;
public Form1()
{
InitializeComponent();
lstMsg.Clear();
lstMsg.View = View.Details;
lstMsg.Columns.Add("Date", 150);
lstMsg.Columns.Add("From", 250);
lstMsg.Columns.Add("Subject", 400);
lstMsg.Columns.Add("Has Attachment", 50);
lstMsg.Columns.Add("Id", 100);
lstMsg.FullRowSelect = true;
}
private void btnRead_Click(object sender, EventArgs e)
{
ConnectToExchangeServer();
TimeSpan ts = new TimeSpan(0, -1, 0, 0);
DateTime date = DateTime.Now.Add(ts);
SearchFilter.IsGreaterThanOrEqualTo filter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, date);
if (exchange != null)
{
FindItemsResults < Item > findResults = exchange.FindItems(WellKnownFolderName.Inbox, filter, new ItemView(50));
foreach(Item item in findResults)
{
EmailMessage message = EmailMessage.Bind(exchange, item.Id);
ListViewItem listitem = new ListViewItem(new[]
{
message.DateTimeReceived.ToString(), message.From.Name.ToString() + "(" + message.From.Address.ToString() + ")", message.Subject, ((message.HasAttachments) ? "Yes" : "No"), message.Id.ToString()
});
lstMsg.Items.Add(listitem);
}
if (findResults.Items.Count <= 0)
{
lstMsg.Items.Add("No Messages found!!");
}
}
}
public void ConnectToExchangeServer()
{
lblMsg.Text = "Connecting to Exchange Server..";
lblMsg.Refresh();
try
{
exchange = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
exchange.Credentials = new WebCredentials("USERNAME", "PASSWORD", "DOMAIN");
exchange.AutodiscoverUrl("USERNAME@DOMAIN");
lblMsg.Text = "Connected to Exchange Server : " + exchange.Url.Host;
lblMsg.Refresh();
}
catch (Exception ex)
{
lblMsg.Text = "Error Connecting to Exchange Server!!" + ex.Message;
lblMsg.Refresh();
}
}
private void btnLoad_Click(object sender, EventArgs e)
{
if (exchange != null)
{
if (lstMsg.Items.Count > 0)
{
ListViewItem item = lstMsg.SelectedItems[0];
if (item != null)
{
string msgid = item.SubItems[4].Text.ToString();
EmailMessage message = EmailMessage.Bind(exchange, new ItemId(msgid));
if (message.HasAttachments && message.Attachments[0] is FileAttachment)
{
FileAttachment fileAttachment = message.Attachments[0] as FileAttachment;
//Change the below Path
fileAttachment.Load(@"C:\\ReadMailFromExchangeServer\\" + fileAttachment.Name);
lblAttach.Text = "Attachment Downloaded : " + fileAttachment.Name;
}
else
{
MessageBox.Show("No Attachments found!!");
}
}
else
{
MessageBox.Show("Please select a Message!!");
}
}
else
{
MessageBox.Show("Messages not loaded!!");
}
}
else
{
MessageBox.Show("Not Connected to Mail Server!!");
}
}
}
}
Reply
Answers (
2
)
UserId in AspNet WebApi
What is .NET CORE & ASP.NET CORE and advantages?