Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单击“插入”按钮时尝试从“详细信息”视图发送电子邮件_C#_Asp.net_Outlook 2010_Detailsview - Fatal编程技术网

C# 单击“插入”按钮时尝试从“详细信息”视图发送电子邮件

C# 单击“插入”按钮时尝试从“详细信息”视图发送电子邮件,c#,asp.net,outlook-2010,detailsview,C#,Asp.net,Outlook 2010,Detailsview,我正在开发一个工单管理web应用程序,用户在其中创建工单。要创建工单,我使用的是详细信息视图,要向主管显示工单,我使用的是gridview 我有一个下拉列表字段: <asp:TemplateField HeaderText="Type_of_Work_Order" SortExpression="Type_of_Work_Order"> <EditItemTempla

我正在开发一个工单管理web应用程序,用户在其中创建工单。要创建工单,我使用的是详细信息视图,要向主管显示工单,我使用的是gridview

我有一个下拉列表字段:

       <asp:TemplateField HeaderText="Type_of_Work_Order" 
                        SortExpression="Type_of_Work_Order">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" 
                                Text='<%# Bind("Type_of_Work_Order") %>'></asp:TextBox>
                        </EditItemTemplate>
     <InsertItemTemplate>
        <asp:DropDownList ID="DropDownList1" DataTextField="Type_of_Work_Order" 
        DataValueField="Type_of_Work_Order" runat="server" Height="29px" Width="599px" 
          SelectedValue = '<%# Bind("Type_of_Work_Order") %>' 
                                onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                                <asp:ListItem>Safety</asp:ListItem>
                                <asp:ListItem>Quality</asp:ListItem>
                                <asp:ListItem>General</asp:ListItem>

  </asp:DropDownList>
 </InsertItemTemplate>

如果您有任何帮助,我们将不胜感激

Microsoft目前不建议也不支持从任何无人值守、非交互式客户端应用程序或组件(包括ASP、ASP.NET、DCOM和NT服务)自动化Microsoft Office应用程序,因为在这种环境下运行Office时,Office可能会表现出不稳定的行为和/或死锁

如果您正在构建一个在服务器端上下文中运行的解决方案,那么您应该尝试使用安全的组件来无人值守地执行。或者,您应该尝试找到至少允许部分代码在客户端运行的替代方案。如果使用服务器端解决方案中的Office应用程序,该应用程序将缺少许多成功运行所需的功能。此外,您将面临整体解决方案稳定性方面的风险。在文章中阅读更多关于这方面的内容


取而代之的是,可以考虑使用Outlook基于扩展的MAPI的.NET.mail命名空间或低级API。如果您只处理Exchange,请参阅EWS。

这是否实际使用Outlook interop发送电子邮件,而不是
System.Net.Mail
()???
if (DropDownList1.Text == Type of Work Order Selected By the User)
{
// Create a Outlook Application and connect to outlook 
Application OutlookApplication = new Application();

// create the MailItem which we want to send 
MailItem email = (MailItem)OutlookApplication.CreateItem(OlItemType.olMailItem);
 // Add a recipient for the email
email.Recipients.Add("**PEOPLE UNDER THE TYPE OF WORK ORDER GROUP**");
 // add subject and body of the email
email.Subject = "Test";
email.Body = "This is a test email to check outlook email sending code";

// add display name, position and attach type for the attachment
string DisplayName = "MyAttachment";
int iPosition = email.Body.Length + 1;
int AttachType = (int)OlAttachmentType.olByValue;
 //now attached the file
Attachment Attach = email.Attachments.Add("C:\\test.txt", AttachType, iPosition, DisplayName);

//send email
email.Send();
}