【发布时间】:2015-03-24 21:14:14
【问题描述】:
我正在尝试(从我的 Exchange Server Outlook)获取我的 Outlook 联系人。 我使用 C# 和 email.Attachments.AddItemAttachment(variable); 我已经连接到 Outlook,并且可以使用我的脚本发送。我加载了所有 Outlook 文件夹。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Office.Interop.Outlook;
//using Microsoft.Office.Interop.Outlook.MAPIFolder;
//Imports outlook = Microsoft.Office.Interop.Outlook
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
RedirectionUrlValidationCallback);
service.Url = new Uri("*******");
service.Credentials = new WebCredentials("******","******"); service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
EmailMessage email = new EmailMessage(service);
/////////////////////////////////////////////////////////////////////
var outlookApplication = new Microsoft.Office.Interop.Outlook.Application();
NameSpace mapiNamespace = outlookApplication.GetNamespace("MAPI");
MAPIFolder contacts = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
for (int i = 1; i < contacts.Items.Count + 1; i++)
{
var contact = (ContactItem)contacts.Items[i];
itemAttachment.Name="contact.FullName";
Console.WriteLine(contact.Email1Address);
Console.WriteLine();
}
var testcontact = "adasd";
/////////////////////////////////////////////////////////////////////
email.ToRecipients.Add("********");
email.Sender = new Microsoft.Exchange.WebServices.Data.EmailAddress("*****");
email.Subject = "Test subj";
email.Body = new MessageBody("Test txt");
email.Attachments.AddItemAttachment(testcontact);
email.SendAndSaveCopy();
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
}
}
有谁知道正确的语法是什么
email.Attachments.AddItemAttachment(testcontact);
?
【问题讨论】:
标签: c# email outlook exchange-server