I'm creating an application that automatically sends word emails via outlook using Outlook.Application Class....
Something weird is happening,
My development machine is on Windows 7, and everything works fine here, the .send() property sends the mail properly even if outlook is closed.
But when i try to put the application on my server which is under windows XP, when the function is called the mail won't be send if outlook is close, it only goes in the outbox, and when i open outlook it will be send... I notices it doesn't happen for every mail adresses too... but most of them have this problem....
so In fact on my server i need to have outlook opened all the time for the mail to be send directly when my function is called, on windows 7 i don't cause the mail is sent directly everytime even if outlook is closed....
Can someone help me about that?
Here is a piece of the code i use to send the mail:
Application oApp = new Outlook.Application();
//Create the new message by using the simplest approach.
MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Inspector oAddSig = null;
oAddSig = oMsg.GetInspector;
oMsg.To = theMail.sendTo;
oMsg.CC = theMail.Cc.Replace(
//Set the basic properties.
oMsg.Subject = theMail.subjectMessage;
//selon le type de message on ouvre soit le devis soit le modele
string chemDevis = "";
Globals.cheminDevis + theMail.dossierMessage + "\\" + theMail.objDevis.cheminDevis;
string theBody = getWordDoc(chemDevis);
oMsg.HTMLBody = theBody;
if (theMail.pieceJointeMessage != "")
string cheminPj = Globals.cheminPjSend + theMail.filialeMessage + "\\" + theMail.dossierMessage + "\\queue\\" + theMail.idMessage + "\\";
string listPj = theMail.pieceJointeMessage.Split(';');
for (int i = 0; i < listPj.Length; i++)
string file = cheminPj + listPj[i].ToString();
String sSource = file;
String sDisplayName = listPj[i].ToString();
// int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Thank you in advance
If the code is only sending emails, its questionable to use a client application to do that job on a server. I recommend that you either write code to use How to send e-mail programmatically by using System.Web.Mail in Visual C# 2005 or in Visual C# .NET or use Exchange Web Services Managed API to accomplish the same thing. HTH
(Introducing the Exchange Web Services Managed API )
William Wegerson (www.OmegaCoder.Com)
- Marked as answer by SamAgain Thursday, February 25, 2010 9:14 AM