2017-04-26 10 views
0

私はローカルマシンから実行するとすべてがうまく動作しますが、サーバーに展開するとエラーが発生します。このエラーが表示されています:asp.netのコードの背後からOutlookを開く

"404 - File or directory not found. 
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." 

これまでのところどのような問題か分かりません。私はonrowコマンドイベントを使用する必要があるので、ユーザーが選択されたコマンドボタンに基づいて別の電子メールを送信することができます。私は見通しを開く必要があり、私は主題と本文の内容、さらにはmailtoをプログラム的に割り当てています。ここ は私のコードです:

protected void GridViews_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 

     SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ToString()); 


     Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application(); 
     Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); 


     if (e.CommandName == "Select") 
     { 

      int rowIndex = Convert.ToInt32(e.CommandArgument); 
      string contractname = gvDetail.Rows[rowIndex].Cells[0].Text; 
      string vendorname = gvDetail.Rows[rowIndex].Cells[1].Text; 

      oMsg.Subject = "test"; 
      oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML; 
      oMsg.HTMLBody = "<p> "test..." + Environment.NewLine + "</p>"; //Here comes your body; 

      oMsg.Display(false); //In order to display it in modal inspector change the argument to true 
     } 
    } 
背後

<asp:GridView ID="gvDetail" runat="server" CssClass="table table-hover table-bordered table-responsive" ForeColor="#333333" GridLines="None" 
       CellPadding="4" PageSize="200" OnRowCommand="GridViews_RowCommand" OnPageIndexChanging="OnPaging_gvDetail" 
       AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true" EnableViewState="True"> 
       <AlternatingRowStyle BackColor="#F3F3F3" /> 
       <Columns> 


        <asp:BoundField DataField="contract_name" HeaderText="Category" /> 
        <asp:BoundField DataField="vendor_name" HeaderText="Vendor Name" /> 


        <asp:ButtonField HeaderText="Reconciliation of Spend Metrics" ButtonType="Image" ImageUrl="~/img/mail.png" ControlStyle-Width="30px" ControlStyle-Height="30px" CommandName="Select" /> 
        <asp:ButtonField HeaderText="Request Call/Meeting with Supplier" ButtonType="Image" ImageUrl="~/img/mail.png" ControlStyle-Width="30px" ControlStyle-Height="30px" CommandName="Select1" /> 

       </Columns> 
       <HeaderStyle CssClass="GridviewScrollHeader" BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> 
       <RowStyle CssClass="GridviewScrollItem" ForeColor="#000066" /> 
       </asp:GridView> 

コード

+0

見つからないディレクトリパスとは何ですか? – Seano666

+0

私は確信していませんが、それは私が得ているエラーです。 – moe

+1

サーバに* Outlookがインストールされていますか?あなたは 'MailMessage'と' SmtpClient'だけを使って考えましたか? – itsme86

答えて

2

あなたのコードは、Outlookにアクセスするためのインタラクティブなユーザー決してありませんサーバー上で実行されていることになります。さらに悪いことに、Outlookはサービス(IISなど)から使用することはできません。

EMLファイルを作成し、Webサイトユーザーへのリンクを提供する - Outlook(クライアント側)は、開いて表示することができます。

関連する問題