2012-07-31 87 views
0

我使用Visual Studio 2010中 我想写功能,打开Outlook窗口,当用户点击一个按钮,发送电子邮件编写项目在asp.net C#。打开Outlook窗口发送电子邮件asp.net

我尝试这样做:

using Outlook = Microsoft.Office.Interop.Outlook; 

Outlook.Application oApp = new Outlook.Application(); 
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem (Outlook.OlItemType.olMailItem); 
oMailItem.To = address; 
// body, bcc etc... 
oMailItem.Display (true); 

但是编译器说有命名空间内微软没有命名空间局。 其实Microsoft Office包括Outlook完全安装在我的电脑中。

我应该包括办公室库到Visual Studio? 问题如何解决?

+0

您是否试图从网页打开Outlook? – yogi 2012-07-31 09:06:59

回答

1

如果使用Microsoft.Office.Interop.Outlook,Outlook必须在服务器上安装(并在服务器上运行,而不是在用户计算机上)。

您是否尝试过使用SmtpClient

System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(); 
     using (m) 
     { 
      //sender is set in web.config: <smtp from="my alias &lt;[email protected]&gt;"> 
      m.To.Add(to); 
      if (!string.IsNullOrEmpty(cc)) 
       m.CC.Add(cc); 
      m.Subject = subject; 
      m.Body = body; 
      m.IsBodyHtml = isBodyHtml; 
      if (!string.IsNullOrEmpty(attachmentName)) 
       m.Attachments.Add(new System.Net.Mail.Attachment(attachmentFile, attachmentName)); 

      System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); 
      try 
      { client.Send(m); } 
      catch (System.Net.Mail.SmtpException) {/*errors can happen*/ } 
     } 
+0

目前我在本地主机上运行项目,所以我的电脑不是服务器?我试过SMTP,但我想打开Outlook正如我上面 – Nurlan 2012-07-31 09:15:35

+0

是说,其实你的计算机是服务器;请记住,您必须在将部署应用程序的服务器上安装Outlook。 – 2012-07-31 09:17:18

+0

在这种情况下,用户如何看到服务器上运行的Outlook窗口? – Nurlan 2012-07-31 09:19:09

1

这个使用Outlook来发送电子邮件与收件人,主题和身体预装。

<A HREF="mailto:[email protected]?subject=this is the subject&body=Hi, This is the message body">send outlook email</A> 
1

而是你试试这样,添加使用Microsoft.Office.Interop.Outlook;参考

 Application app = new Application(); 
     NameSpace ns = app.GetNamespace("mapi"); 
     ns.Logon("Email-Id", "Password", false, true); 
     MailItem message = (MailItem)app.CreateItem(OlItemType.olMailItem); 
     message.To = "To-Email_ID"; 
     message.Subject = "A simple test message"; 
     message.Body = "This is a test. It should work"; 

     message.Attachments.Add(@"File_Path", Type.Missing, Type.Missing, Type.Missing); 

     message.Send(); 
     ns.Logoff(); 
相关问题