PC Review


Reply
Thread Tools Rate Thread

C# and Outlook

 
 
Jeff
Guest
Posts: n/a
 
      14th Sep 2006
I am trying to send emails from my application (not using a plugin, that
will come later), I can create an email and add attachments. I can fill in
the body etc. Word works for the editor. So mostly what I want.
My issue is I would like to retain the signature block that exists when I
insert my body into the message.

Any help would be appreciated. Here is the code I am using:

//Initialize the envelope values.
string strTo = "(E-Mail Removed)";
string strBCC = "(E-Mail Removed)";
string strCC = "(E-Mail Removed)";
string strSubject = "Outlook Automation";
string strBody = "HTMLPage1.htm";

//Automate the Word document.
wApp = new Word.Application();
wApp.Visible = false;
object template = System.Reflection.Missing.Value;
object newTemplate = System.Reflection.Missing.Value;
object documentType = Word.WdNewDocumentType.wdNewEmailMessage;
object visible = false;
wApp.Visible = false;
Word._Document doc = wApp.Documents.Add(
ref template,
ref newTemplate,
ref documentType,
ref visible);

//Automate the Outlook mail item.
Microsoft.Office.Interop.Outlook.MailItem mItem =
(Outlook.MailItem)doc.MailEnvelope.Item;
mItem.To = strTo;
mItem.BCC = strBCC;
mItem.CC = strCC;
mItem.Subject = strSubject;

// Attach a file
String sSource = "C:\\TEMP\\org.sql";
String sDisplayName = "MyFirstAttachment";
int iPosition = 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach = mItem.Attachments.Add(sSource, iAttachType,
iPosition, sDisplayName);

// Set the body
// Comment out and the signature stays
mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mItem.HTMLBody =
"<html><head><title></title></head>"
+"<body><p>This is a text from my application</p>"
+"<br /><b>Some bold stuff</b>"
+"<br /></body></html>";

wApp.Visible = true;

// Loop until there are no more references to release.
while (Marshal.ReleaseComObject(mItem) > 0) ;
mItem = null;

// Invoke the .NET garbage collector.
GC.Collect();
GC.WaitForPendingFinalizers();


 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      15th Sep 2006
mItem.HTMLBody = mItem.HTMLBody & whatever

You're overwriting what's there already. Either concatenate your text to the
existing HTMLBody or concatenate the existing HTMLBody to your text.


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Jeff" <(E-Mail Removed)> wrote in message
news:EedOg.921$(E-Mail Removed)...
>I am trying to send emails from my application (not using a plugin, that
>will come later), I can create an email and add attachments. I can fill in
>the body etc. Word works for the editor. So mostly what I want.
> My issue is I would like to retain the signature block that exists when I
> insert my body into the message.
>
> Any help would be appreciated. Here is the code I am using:
>
> //Initialize the envelope values.
> string strTo = "(E-Mail Removed)";
> string strBCC = "(E-Mail Removed)";
> string strCC = "(E-Mail Removed)";
> string strSubject = "Outlook Automation";
> string strBody = "HTMLPage1.htm";
>
> //Automate the Word document.
> wApp = new Word.Application();
> wApp.Visible = false;
> object template = System.Reflection.Missing.Value;
> object newTemplate = System.Reflection.Missing.Value;
> object documentType = Word.WdNewDocumentType.wdNewEmailMessage;
> object visible = false;
> wApp.Visible = false;
> Word._Document doc = wApp.Documents.Add(
> ref template,
> ref newTemplate,
> ref documentType,
> ref visible);
>
> //Automate the Outlook mail item.
> Microsoft.Office.Interop.Outlook.MailItem mItem =
> (Outlook.MailItem)doc.MailEnvelope.Item;
> mItem.To = strTo;
> mItem.BCC = strBCC;
> mItem.CC = strCC;
> mItem.Subject = strSubject;
>
> // Attach a file
> String sSource = "C:\\TEMP\\org.sql";
> String sDisplayName = "MyFirstAttachment";
> int iPosition = 1;
> int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
> Outlook.Attachment oAttach = mItem.Attachments.Add(sSource, iAttachType,
> iPosition, sDisplayName);
>
> // Set the body
> // Comment out and the signature stays
> mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
> mItem.HTMLBody =
> "<html><head><title></title></head>"
> +"<body><p>This is a text from my application</p>"
> +"<br /><b>Some bold stuff</b>"
> +"<br /></body></html>";
>
> wApp.Visible = true;
>
> // Loop until there are no more references to release.
> while (Marshal.ReleaseComObject(mItem) > 0) ;
> mItem = null;
>
> // Invoke the .NET garbage collector.
> GC.Collect();
> GC.WaitForPendingFinalizers();
>
>


 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      15th Sep 2006
Ok when I do that though (access the body) I get the outlook warning message
that a possible malicious program is accessing the outlook program? Any
ideas oh how to get past that? (also this does not work, since the body is
actually not there when the show is called it almost looks like I need to
wait for some respons that the window has actually been opened)

"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> mItem.HTMLBody = mItem.HTMLBody & whatever
>
> You're overwriting what's there already. Either concatenate your text to
> the existing HTMLBody or concatenate the existing HTMLBody to your text.
>
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "Jeff" <(E-Mail Removed)> wrote in message
> news:EedOg.921$(E-Mail Removed)...
>>I am trying to send emails from my application (not using a plugin, that
>>will come later), I can create an email and add attachments. I can fill in
>>the body etc. Word works for the editor. So mostly what I want.
>> My issue is I would like to retain the signature block that exists when I
>> insert my body into the message.
>>
>> Any help would be appreciated. Here is the code I am using:
>>
>> //Initialize the envelope values.
>> string strTo = "(E-Mail Removed)";
>> string strBCC = "(E-Mail Removed)";
>> string strCC = "(E-Mail Removed)";
>> string strSubject = "Outlook Automation";
>> string strBody = "HTMLPage1.htm";
>>
>> //Automate the Word document.
>> wApp = new Word.Application();
>> wApp.Visible = false;
>> object template = System.Reflection.Missing.Value;
>> object newTemplate = System.Reflection.Missing.Value;
>> object documentType = Word.WdNewDocumentType.wdNewEmailMessage;
>> object visible = false;
>> wApp.Visible = false;
>> Word._Document doc = wApp.Documents.Add(
>> ref template,
>> ref newTemplate,
>> ref documentType,
>> ref visible);
>>
>> //Automate the Outlook mail item.
>> Microsoft.Office.Interop.Outlook.MailItem mItem =
>> (Outlook.MailItem)doc.MailEnvelope.Item;
>> mItem.To = strTo;
>> mItem.BCC = strBCC;
>> mItem.CC = strCC;
>> mItem.Subject = strSubject;
>>
>> // Attach a file
>> String sSource = "C:\\TEMP\\org.sql";
>> String sDisplayName = "MyFirstAttachment";
>> int iPosition = 1;
>> int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
>> Outlook.Attachment oAttach = mItem.Attachments.Add(sSource, iAttachType,
>> iPosition, sDisplayName);
>>
>> // Set the body
>> // Comment out and the signature stays
>> mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
>> mItem.HTMLBody =
>> "<html><head><title></title></head>"
>> +"<body><p>This is a text from my application</p>"
>> +"<br /><b>Some bold stuff</b>"
>> +"<br /></body></html>";
>>
>> wApp.Visible = true;
>>
>> // Loop until there are no more references to release.
>> while (Marshal.ReleaseComObject(mItem) > 0) ;
>> mItem = null;
>>
>> // Invoke the .NET garbage collector.
>> GC.Collect();
>> GC.WaitForPendingFinalizers();
>>
>>

>



 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      16th Sep 2006
Your options for the security are explained at
http://www.outlookcode.com/d/sec.htm.

Wait for the first Inspector.Activate event to fire for the item that's
being opened.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Jeff" <(E-Mail Removed)> wrote in message
news:BjBOg.1254$(E-Mail Removed)...
> Ok when I do that though (access the body) I get the outlook warning
> message that a possible malicious program is accessing the outlook
> program? Any ideas oh how to get past that? (also this does not work,
> since the body is actually not there when the show is called it almost
> looks like I need to wait for some respons that the window has actually
> been opened)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
outlook add-in, add-in for outlook, outlook contact capture, capturecontacts into outlook, outlook add-on, address capture, capture name,addresses, import contacts to Outlook, transfer contact details into outlook Dhan Microsoft Outlook Program Addins 0 24th Apr 2010 09:03 AM
Programattically setting Outlook signatures (Outlook 2003 and Outlook 2000) Chris Microsoft Outlook 2 17th Jul 2007 03:37 PM
Outlook 2002: "...Outlook Requires Outlook Express 4.01 or greater =?Utf-8?B?Q2hyaXMgRw==?= Microsoft Outlook Discussion 4 8th Dec 2004 07:49 PM
Automatically Print Emails with Outlook 2000, Outlook 2002, or Outlook Express Clayton Microsoft Outlook 2 13th Dec 2003 03:28 PM
Outlook 2002 (Office XP Suite) Outlook hangs, task manger "Outlook Not Respondin Mike Microsoft Outlook 0 10th Jul 2003 01:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:22 AM.