Outlook Mail at client side with attachment from web server

Answered Outlook Mail at client side with attachment from web server

  • 21 มกราคม 2555 7:45
     
     

    Hi

    I have a requirement where I have to create a PDF report on the web server and to create a mail in the draft folder in the outlook mail client on the client side with the PDF on the server attached to it. For this I have used javascript code like this .....

    ---------------------------------------

           try {
                objOutlookExpress = new ActiveXObject("Outlook.Application");
            }
            catch (err) {
                alert(err.message +
                        "\n Ensure that the 'scripting of ActiveX controls not marked safe' is enabled for the browser");

                return;
            }

            objOutlookMsg = objOutlookExpress.CreateItem(0)
            objOutlookMsg.To = "abc@xyz.com";
            objOutlookMsg.Subject = "subject";
            objOutlookMsg.HTMLBody = "Mail Body";
            try
            {
                objOutlookMsg.Attachments.Add("http://192.168.0.236:87/temp/BEXFCLIPBUMCC0001_20012012_31012012.pdf", 1, 1, "Attachment");

                objOutlookMsg.Save();           
                alert("An email with the quotation is saved in the Outlook draft folder");

            }
            catch (err) {
                alert(err.message);
                return;
            }

    -----------------------------------------------------

    I have used the URI of the generated file on the web server as the mail attachment file path. The web application uses windows authentication. On some installations it works OK, but in some other it says that the "file name or directory name is invalid". What could be the possible problem for this and how to get around this problem 

    • ย้ายโดย Leo Liu - MSFTModerator 24 มกราคม 2555 6:36 Moved for better support. (From:Visual C# General)
    •  

ตอบทั้งหมด

  • 21 มกราคม 2555 12:40
     
     

    Have you tried with Internet Explorer of Firefox? Does the error appear only on certain web browsers?


    Marco Minerva [MCPD]
    Blog: http://blogs.ugidotnet.org/marcom
    Twitter: @marcominerva
  • 21 มกราคม 2555 17:09
     
     คำตอบ

    Do double check with  this.

    Sending Email with attachment in ASP.NET using SMTP Server

    http://www.codeproject.com/Articles/10828/Sending-Email-with-attachment-in-ASP-NET-using-SMT

    chanmm


    chanmm
    • ทำเครื่องหมายเป็นคำตอบโดย Leo Liu - MSFTModerator 30 มกราคม 2555 5:48
    •  
  • 23 มกราคม 2555 6:07
     
     
    I have tested this with IE 8.0. With one web application deployment it works, and does not work for another deployment (both use IIS 6.0, windows 2003 serer and windows authentication)
  • 23 มกราคม 2555 8:48
     
     

    As you use Javascript, the script runs on client, so the problem resides on the client, not on the server. Have you verified that the URL of the PDF that you're trying to attach is reachble, for example if you copy the URL in the browser address bar?


    Marco Minerva [MCPD]
    Blog: http://blogs.ugidotnet.org/marcom
    Twitter: @marcominerva
  • 24 มกราคม 2555 6:37
    ผู้ดูแล
     
     
    Hi Debjit,

    I am moving your thread into the JScript for the .NET Framework Forum for dedicated support.
    Have a nice day, 
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
  • 31 มกราคม 2555 8:44
     
     
    Yes, the file opens. If I type "http://Server/Folder/File.pdf the PDF opens. However it pops up a domain user id & password window(as the web application and IIS is configured to use windows authentication) . If I enter my domain user id and password the PDF file opens. Could this be the problem ? The Outlook ActieX is trying to access the file on the server and with no way of entering user id and pasword the server rejects the request which causes the Outlook ActiveX to fail to attach the file from the server.
  • 7 กุมภาพันธ์ 2555 6:19
     
     

    Any ideas anyone on the possible reason(s) for this problem? I would appreciate your help on this.

    Thanks,

    Debjit

  • 22 มิถุนายน 2555 10:04
     
     

    Hi Debijt...

    I ave the same Problem using javascript tryng to get a document as an email attachment from sharepoint..

    the problem seems to be that  either - outlook has no rights to download eventhough IE starts it and the List has been added to synchronized with outlook...
    OR the síte is not added to trusted sites... something like that..
    have you solved your problem meanwhile ?

    and when... how ? ;))

    rgerds

    Leo

     

  • 22 มิถุนายน 2555 10:24
     
     

    Hi Debijt...

    I found the solution.. the error ist that you use "  in

    objOutlookMsg.Attachments.Add("http://192.168.0.236:87/temp/BEXFCLIPBUMCC0001_20012012_31012012.pdf", 1, 1, "Attachment");

    Add .. try ' instead of this..

    var outlookApp = new ActiveXObject("Outlook.Application");
    var nameSpace = outlookApp.getNameSpace("MAPI");
    mailFolder = nameSpace.getDefaultFolder(6);
    theMailItem = mailFolder.Items.add('IPM.NotemA');
    //var theMailItem = outlookApp.CreateItem(0);
    // theMailItem.Subject = "";
    // theMailItem.To = "";
    // theMailItem.HTMLBody = "";
    theMailItem.Attachments.add('https://portal.xxxxx.de/yyyyy.pdf');
    theMailItem.display(0);