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 = "na**@domain.com";
string strBCC = "na**@domain.com";
string strCC = "na**@domain.com";
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(); 3 10630
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" <je*********@lindholm.orgwrote in message
news:Ee***************@newssvr12.news.prodigy.com. ..
>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 = "na**@domain.com";
string strBCC = "na**@domain.com";
string strCC = "na**@domain.com";
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();
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]" <ke*******@mvps.orgwrote in message
news:Oi**************@TK2MSFTNGP06.phx.gbl...
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" <je*********@lindholm.orgwrote in message
news:Ee***************@newssvr12.news.prodigy.com. ..
>>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 = "na**@domain.com"; string strBCC = "na**@domain.com"; string strCC = "na**@domain.com"; 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();
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" <je*********@lindholm.orgwrote in message
news:Bj****************@newssvr12.news.prodigy.com ...
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)
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fritz Switzer |
last post by:
Can anyone provide a small snippet in C# that pulls out the Contacts in
Outlook XP.
I've seen a couple of examples in C++ and VB in previous newsgroup posts,
but either the originals didn't work...
|
by: John |
last post by:
Hi
When I open a new outlook email from vb.net, sometimes outlook is very slow
to appear or occasionally outlook freezes completely. I am targeting mixed
office2000/xp environments so I am...
|
by: Srinivas |
last post by:
hi all
how to access the outlook user profiles through VB.net
any help....
thanks in advanc
Srinivas
|
by: George McCullen |
last post by:
I have an Outlook 2003 using Exchange Server 2003 Public Contacts Folder containing 20,000 Contacts. I am writing a VB .Net 2003 program that loops through all the contacts in a "for each oCt in...
|
by: John |
last post by:
Hi
I am trying to access outlook contacts folders and delete the contacts that
do not contain a certain category value in the categories field. I have
written the below code but am stuck with...
|
by: Chris Thunell |
last post by:
I'm trying to loop through an exchange public folder contact list, get some
information out of each item, and then put it into a vb.net datatable. I
run though the code and all works fine until i...
|
by: Li Pang |
last post by:
Hi,
I used following codes to pass a message item from CDO to Outlook. They
worked fine when I used outlook 2000, but get an error of "Specified cast is
not valid." when I used Outlook 2003....
|
by: wizzbangca |
last post by:
Hi everyone. Having problems with a utility I am writing for work.
The previous IT Director thoughtfully allowed 3 (2000, xp, 2003)
versions of outlook to be installed rather than 1. Now I need...
|
by: JC |
last post by:
Anybody knows what problem has this code? I think, in the Garbage
Collector? You know the Solution?
The program in the test's case, whit 350 contacts, run OK before number
86. The error is a...
|
by: Brian Hampson |
last post by:
I recently upgraded to Outlook 2007 B2TR and have found that I can no
longer code against MAPI.DLL It's gone :(
Using C#, I used to get the MAPI session, and from that I could change
the out of...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |