本文整理汇总了C#中Microsoft.Office.Interop.Outlook.Application.CreateItem方法的典型用法代码示例。如果您正苦于以下问题:C# Application.CreateItem方法的具体用法?C# Application.CreateItem怎么用?C# Application.CreateItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Outlook.Application
的用法示例。
在下文中一共展示了Application.CreateItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application application = new Outlook.Application();
Outlook.NameSpace ns = application.GetNamespace("MAPI");
try
{
//get selected mail item
Object selectedObject = application.ActiveExplorer().Selection[1];
Outlook.MailItem selectedMail = (Outlook.MailItem)selectedObject;
//create message
Outlook.MailItem newMail = application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
newMail.Recipients.Add(ReadFile());
newMail.Subject = "SPAM";
newMail.Attachments.Add(selectedMail, Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem);
newMail.Send();
selectedMail.Delete();
System.Windows.Forms.MessageBox.Show("Spam notification has been sent.");
}
catch
{
System.Windows.Forms.MessageBox.Show("You must select a message to report.");
}
}
示例2: Execute
protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
{
// Create an Outlook Application object.
Outlook.Application outlookApp = new Outlook.Application();
// Create a new TaskItem.
Outlook.TaskItem newTask = (Outlook.TaskItem)outlookApp.CreateItem(Outlook.OlItemType.olTaskItem);
// Configure the task at hand and save it.
newTask.Body = "Workflow Generated Task";
newTask.DueDate = DateTime.Now;
newTask.Importance = Outlook.OlImportance.olImportanceHigh;
if (this.Parent.Parent is ParallelActivity)
{
newTask.Subject = (this.Parent.Parent.Parent.Activities[1] as DummyActivity).TitleProperty;
if ((this.Parent.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
{
MessageBox.Show("Creating Outlook Task");
newTask.Save();
}
}
else if (this.Parent.Parent is SequentialWorkflowActivity)
{
newTask.Subject = (this.Parent.Parent.Activities[1] as DummyActivity).TitleProperty;
if ((this.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
{
MessageBox.Show("Creating Outlook Task");
newTask.Save();
}
}
return ActivityExecutionStatus.Closed;
}
示例3: SendEMailThroughOutlook
public static void SendEMailThroughOutlook(List<string> toList, string subject, string msg, string attachementFileName = null )
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody += msg;
//Add an attachment.
String sDisplayName = "Coopcheck Log";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
// now attached the file
Outlook.Attachment oAttach = oMsg.Attachments.Add(attachementFileName, iAttachType, iPosition, sDisplayName);
//Subject line
oMsg.Subject = subject;
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
foreach (var i in toList)
{
Outlook.Recipient oRecip = (Outlook.Recipient) oRecips.Add(i);
oRecip.Resolve();
}
oMsg.Send();
}
示例4: AddAppointment
public void AddAppointment(Appointment apt)
{
try
{
Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment
oAppointment.Subject = apt.Subject;
oAppointment.Body = apt.Body;
oAppointment.Location = apt.Location;
oAppointment.Start = Convert.ToDateTime(apt.StartTime);
oAppointment.End = Convert.ToDateTime(apt.EndTime);
oAppointment.ReminderSet = true;
oAppointment.ReminderMinutesBeforeStart = apt.ReminderMinutesBeforeStart;
oAppointment.Importance = Outlook.OlImportance.olImportanceHigh;
oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
oAppointment.RequiredAttendees = apt.RequiredAttendees;
oAppointment.Save();
Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
// email address to send to
mailItem.To = apt.RequiredAttendees +";" + apt.Organizer; //" [email protected]";
// send
mailItem.Send();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\r\n" + ex.InnerException + "\r\n" + "\r\n");
}
}
示例5: ThisAddIn_Startup
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Create an object of type Outlook.Application
Outlook.Application objOutlook = new Outlook.Application();
//Create an object of type olMailItem
Outlook.MailItem oIMailItem = objOutlook.CreateItem(Outlook.OlItemType.olMailItem);
//Set properties of the message file e.g. subject, body and to address
//Set subject
oIMailItem.Subject = "This MSG file is created using Office Automation.";
//Set to (recipient) address
oIMailItem.To = "[email protected]";
//Set body of the email message
oIMailItem.HTMLBody = "<html><p>This MSG file is created using VBA code.</p>";
//Add attachments to the message
oIMailItem.Attachments.Add("image.bmp");
oIMailItem.Attachments.Add("pic.jpeg");
//Save as Outlook MSG file
oIMailItem.SaveAs("testvba.msg");
//Open the MSG file
oIMailItem.Display();
}
示例6: Execute
protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
{
// Create an Outlook Application object.
Outlook.Application outlookApp = new Outlook.Application();
// Create a new TaskItem.
Outlook.NoteItem newNote = (Outlook.NoteItem)outlookApp.CreateItem(Outlook.OlItemType.olNoteItem);
// Configure the task at hand and save it.
if (this.Parent.Parent is ParallelActivity)
{
newNote.Body = (this.Parent.Parent.Parent.Activities[1] as DummyActivity).TitleProperty;
if ((this.Parent.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
{
MessageBox.Show("Creating Outlook Note");
newNote.Save();
}
}
else if (this.Parent.Parent is SequentialWorkflowActivity)
{
newNote.Body = (this.Parent.Parent.Activities[1] as DummyActivity).TitleProperty;
if ((this.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
{
MessageBox.Show("Creating Outlook Note");
newNote.Save();
}
}
return ActivityExecutionStatus.Closed;
}
示例7: CreateOutlookEmail
}//end of Email Method
public static void CreateOutlookEmail(List<string> toList, string subject, string msg, string attachementFileName = null)
{
try
{
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = subject;
Outlook.Recipients oRecips = mailItem.Recipients;
if (toList != null)
{
foreach (var i in toList)
{
Outlook.Recipient oRecip = oRecips.Add(i);
oRecip.Resolve();
}
}
if (attachementFileName != null)
{
//int iPosition = (int) mailItem.Body.Length + 1;
//int iAttachType = (int) Outlook.OlAttachmentType.olByValue;
//now attached the file
mailItem.Attachments.Add(attachementFileName);
}
mailItem.HTMLBody += msg;
mailItem.Display(true);
}
catch (Exception eX)
{
throw new Exception("cDocument: Error occurred trying to Create an Outlook Email"
+ Environment.NewLine + eX.Message);
}
}
示例8: sendEmail
private void sendEmail(EmailObject eml)
{
string myDate = today.ToString("dd MMMM yyyy");
//new outlook instance
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mail = app.CreateItem(Outlook.OlItemType.olMailItem);
{
string[] files = Directory.GetFiles(AttachmentDestination);
int fileCount = 0;
foreach (string file in files)
{
Console.WriteLine("attatching file : " + file);
mail.Attachments.Add(file);
fileCount++;
}
if (fileCount > 0)
{
mail.Importance = Outlook.OlImportance.olImportanceHigh;
mail.Subject = myDate + " " + eml.EmailSubject;
mail.To = eml.Emails;
mail.Body = eml.EmailBody;
Console.WriteLine("sending...");
mail.Send();
}
}
}
示例9: CreateRecurringAppointment
private void CreateRecurringAppointment()
{
Outlook.Application outlookApp = new Outlook.Application();
try
{
Outlook.AppointmentItem appt = outlookApp.CreateItem(
Outlook.OlItemType.olAppointmentItem)
as Outlook.AppointmentItem;
appt.Subject = "Customer Review";
appt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
appt.Location = "36/2021";
appt.Start = DateTime.Parse("10/20/2006 10:00 AM");
appt.End = DateTime.Parse("10/20/2006 11:00 AM");
appt.Body = "Testing";
Outlook.Recipient recipRequired =
appt.Recipients.Add("Ryan Gregg");
recipRequired.Type =
(int)Outlook.OlMeetingRecipientType.olRequired;
Outlook.Recipient recipOptional =
appt.Recipients.Add("Peter Allenspach");
recipOptional.Type =
(int)Outlook.OlMeetingRecipientType.olOptional;
Outlook.Recipient recipConf =
appt.Recipients.Add("Conf Room 36/2021 (14) AV");
recipConf.Type =
(int)Outlook.OlMeetingRecipientType.olResource;
appt.Recipients.ResolveAll();
appt.Display(false);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show("The following error occurred: " + ex.Message);
}
}
示例10: SendEmailUsingOutLook
public void SendEmailUsingOutLook(string witBody,String witName, List<Docs> docs)
{
Microsoft.Office.Interop.Outlook.Application outlookApplication =
new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem email =
(Microsoft.Office.Interop.Outlook.MailItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
email.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;
email.Subject = witName;
email.HTMLBody = witBody;
if (docs != null && docs.Count > 0) {
foreach (var doc in docs) {
if (doc.docId != null)
{
email.Attachments.Add(doc.localPath + "" + doc.fileName, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 100000, Type.Missing);
}
}
}
email.Display(true);
}
示例11: ThisAddIn_Startup
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Microsoft.Office.Interop.Outlook._Application OutlookObject = new Microsoft.Office.Interop.Outlook.Application();
//Create a new Contact Item
Microsoft.Office.Interop.Outlook.ContactItem contact = OutlookObject.CreateItem(
Microsoft.Office.Interop.Outlook.OlItemType.olContactItem);
//Set different properties of this Contact Item.
contact.FirstName = "Mellissa";
contact.LastName = "MacBeth";
contact.JobTitle = "Account Representative";
contact.CompanyName = "Contoso Ltd.";
contact.OfficeLocation = "36/2529";
contact.BusinessTelephoneNumber = "4255551212 x432";
contact.BusinessAddressStreet = "1 Microsoft Way";
contact.BusinessAddressCity = "Redmond";
contact.BusinessAddressState = "WA";
contact.BusinessAddressPostalCode = "98052";
contact.BusinessAddressCountry = "United States of America";
contact.Email1Address = "[email protected]";
contact.Email1AddressType = "SMTP";
contact.Email1DisplayName = "Melissa MacBeth ([email protected])";
//Save the Contact to disc
contact.SaveAs("OutlookContact.vcf", OlSaveAsType.olVCard);
}
示例12: exportToMail_Click
private void exportToMail_Click(object sender, EventArgs e)
{
Outlook.Application oApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = "[email protected]";
oMailItem.HTMLBody = this.generateHTML();
oMailItem.Display(true);
}
示例13: SendMail
public bool SendMail(DbEmail email)
{
Outlook.Attachment oAttach;
try
{
// Create the Outlook application by using inline initialization.
Outlook.Application oApp = new Outlook.Application();
//Create the new message by using the simplest approach.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
//Add a recipient
Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add(email.Recipient);
oRecip.Resolve();
//Set the basic properties.
oMsg.Subject = email.Subject;
oMsg.Body = email.Body;
//Add an attachment
//if (email.Attachments.Count > 0)
//{
// for (int i = 0; i < email.Attachments.Count(); i++)
// {
// String sSource = email.Attachments[i];
// String sDisplayName = email.Subject;
// int iPosition = (int)oMsg.Body.Length + 1;
// int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
// oAttach = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName);
// }
//}
// If you want to, display the message.
// oMsg.Display(true); //modal
//Send the message.
oMsg.Save();
//(oMsg as _Outlook.MailItem).Send();
//Outlook.Account account = oApp.Session.Accounts[email.Sender];
//oMsg.SendUsingAccount = account;
((Outlook._MailItem)oMsg).Send();
//Explicitly release objects.
oRecip = null;
oAttach = null;
oMsg = null;
oApp = null;
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
//Label1.Text = ex.Message + ex.StackTrace;
return false;
}
}
示例14: SendMail
public void SendMail(string subject, string body)
{
OutlookApp.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
OutlookApp.MailItem email = (OutlookApp.MailItem)outlook.CreateItem(OutlookApp.OlItemType.olMailItem);
email.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
email.Subject = subject;
email.HTMLBody = body;
email.Display(false);
}
示例15: OutlookEmailSender2
public OutlookEmailSender2()
{
Outlook.Application olApplication = new Outlook.Application();
Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi");
olNameSpace.Logon(Type.Missing, Type.Missing, true, true);
olMailItem = (Outlook.MailItem)olApplication.CreateItem(Outlook.OlItemType.olMailItem);
olRecipients = olMailItem.Recipients;
olApplication.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(olApplication_ItemSend);
}