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.co m";
string strBCC = "na**@domain.co m";
string strCC = "na**@domain.co m";
string strSubject = "Outlook Automation";
string strBody = "HTMLPage1.htm" ;
//Automate the Word document.
wApp = new Word.Applicatio n();
wApp.Visible = false;
object template = System.Reflecti on.Missing.Valu e;
object newTemplate = System.Reflecti on.Missing.Valu e;
object documentType = Word.WdNewDocum entType.wdNewEm ailMessage;
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.Offic e.Interop.Outlo ok.MailItem mItem =
(Outlook.MailIt em)doc.MailEnve lope.Item;
mItem.To = strTo;
mItem.BCC = strBCC;
mItem.CC = strCC;
mItem.Subject = strSubject;
// Attach a file
String sSource = "C:\\TEMP\\org. sql";
String sDisplayName = "MyFirstAttachm ent";
int iPosition = 1;
int iAttachType = (int)Outlook.Ol AttachmentType. olByValue;
Outlook.Attachm ent oAttach = mItem.Attachmen ts.Add(sSource, iAttachType,
iPosition, sDisplayName);
// Set the body
// Comment out and the signature stays
mItem.BodyForma t = Outlook.OlBodyF ormat.olFormatH TML;
mItem.HTMLBody =
"<html><head><t itle></title></head>"
+"<body><p>T his 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.Releas eComObject(mIte m) 0) ;
mItem = null;
// Invoke the .NET garbage collector.
GC.Collect();
GC.WaitForPendi ngFinalizers(); 3 10650
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*********@li ndholm.orgwrote in message
news:Ee******** *******@newssvr 12.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.co m";
string strBCC = "na**@domain.co m";
string strCC = "na**@domain.co m";
string strSubject = "Outlook Automation";
string strBody = "HTMLPage1.htm" ;
//Automate the Word document.
wApp = new Word.Applicatio n();
wApp.Visible = false;
object template = System.Reflecti on.Missing.Valu e;
object newTemplate = System.Reflecti on.Missing.Valu e;
object documentType = Word.WdNewDocum entType.wdNewEm ailMessage;
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.Offic e.Interop.Outlo ok.MailItem mItem =
(Outlook.MailIt em)doc.MailEnve lope.Item;
mItem.To = strTo;
mItem.BCC = strBCC;
mItem.CC = strCC;
mItem.Subject = strSubject;
// Attach a file
String sSource = "C:\\TEMP\\org. sql";
String sDisplayName = "MyFirstAttachm ent";
int iPosition = 1;
int iAttachType = (int)Outlook.Ol AttachmentType. olByValue;
Outlook.Attachm ent oAttach = mItem.Attachmen ts.Add(sSource, iAttachType,
iPosition, sDisplayName);
// Set the body
// Comment out and the signature stays
mItem.BodyForma t = Outlook.OlBodyF ormat.olFormatH TML;
mItem.HTMLBody =
"<html><head><t itle></title></head>"
+"<body><p>T his 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.Releas eComObject(mIte m) 0) ;
mItem = null;
// Invoke the .NET garbage collector.
GC.Collect();
GC.WaitForPendi ngFinalizers();
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******** ******@TK2MSFTN GP06.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*********@li ndholm.orgwrote in message
news:Ee******** *******@newssvr 12.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.co m"; string strBCC = "na**@domain.co m"; string strCC = "na**@domain.co m"; string strSubject = "Outlook Automation"; string strBody = "HTMLPage1.htm" ;
//Automate the Word document. wApp = new Word.Applicatio n(); wApp.Visible = false; object template = System.Reflecti on.Missing.Valu e; object newTemplate = System.Reflecti on.Missing.Valu e; object documentType = Word.WdNewDocum entType.wdNewEm ailMessage; object visible = false; wApp.Visible = false; Word._Docume nt doc = wApp.Documents. Add( ref template, ref newTemplate, ref documentType, ref visible);
//Automate the Outlook mail item. Microsoft.Offi ce.Interop.Outl ook.MailItem mItem = (Outlook.MailI tem)doc.MailEnv elope.Item; mItem.To = strTo; mItem.BCC = strBCC; mItem.CC = strCC; mItem.Subjec t = strSubject;
// Attach a file String sSource = "C:\\TEMP\\org. sql"; String sDisplayName = "MyFirstAttachm ent"; int iPosition = 1; int iAttachType = (int)Outlook.Ol AttachmentType. olByValue; Outlook.Attach ment oAttach = mItem.Attachmen ts.Add(sSource, iAttachType, iPosition, sDisplayName);
// Set the body // Comment out and the signature stays mItem.BodyForm at = Outlook.OlBodyF ormat.olFormatH TML; mItem.HTMLBo dy = "<html><head><t itle></title></head>" +"<body><p>T his 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.Releas eComObject(mIte m) 0) ; mItem = null;
// Invoke the .NET garbage collector. GC.Collect() ; GC.WaitForPend ingFinalizers() ;
Your options for the security are explained at http://www.outlookcode.com/d/sec.htm.
Wait for the first Inspector.Activ ate 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*********@li ndholm.orgwrote in message
news:Bj******** ********@newssv r12.news.prodig y.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 or my conversion skills are weak. And
if I have to use tlbimp.exe what is the right file to use.
Thanks for the help.
--
Fritz
|
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 using the office2000 interop dlls
generated by vs.net by adding office 2000 com reference.
Any one else noticed this problem when targeting office2000/xp mixed
environments? Is there a better, more robust way to do this? Am I better off
using late...
|
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 oItems" loop. After about 250 contacts, the program gives an InvalidCastException Error on the for each loop. I notice that Outlook's memory keeps increasing (using the task manager) until it reaches around 20,000K. When I run the program a second...
|
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 the error on the indicated line.
Any help would be appreciated.
Thanks
Regards
| |
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 get to item 250 i get a
"system.invalid cast exception" and "specified cast is not valid". Once i
get this error and try to go to the next record.. every record after gets
the same error... It's like the com connection to outlook has been lost....
|
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. Anybody has an ideal?
Dim outlookMsg AsMicrosoft.Office.Interop.Outlook.MailItem
Dim adoMsg As MAPI.Message
outlookMsg =
Microsoft.Office.Interop.Outlook.Application.Session.GetItemFromID(cdoMsg.ID)
|
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 the
utility to work for all 3 versions. A previous post suggested
creating objects to detect the version of outlook, which I tried with
success. But, that's as far as I can get. No one out there shows how
to go beyond version detection to...
|
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 "Array index out of bounds".
Microsoft.Office.Interop.Outlook._Application olApp = new
Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook._NameSpace olNs =
olApp.GetNamespace("MAPI");
|
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 office. No longer. Does anyone know how to do this using
the new Microsoft.Office.Core and Microsoft.Office.Outlook DLL's that
are supposed to be the new replacements?
Here's what I had that worked until Outlook 2007 came around:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |