none
Problem with Outlook Automation

    Question

  • Hello,

    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:



    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);

    Outlook.

    Inspector oAddSig = null;

    oAddSig = oMsg.GetInspector;

    oMsg.To = theMail.sendTo;

    oMsg.CC = theMail.Cc.Replace(

    ',',';');

    oMsg.BCC =

    "vincent@*****.com;jerome@*****.com";

     

    //Set the basic properties.

    oMsg.Subject = theMail.subjectMessage;

     

    //selon le type de message on ouvre soit le devis soit le modele

     

    string chemDevis = "";

    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;

    oMsg.Attachments.Add(sSource, iAttachType,

    null, null);

    }

    }

     

     

    oMsg.Display(

    false);

    oMsg.Save();

    oMsg.Send();

    oAddSig =

    null;

    oMsg =

    null;

    oApp =

    null;


    Thank you in advance
    Friday, February 19, 2010 3:27 AM

Answers