2012-09-20 67 views
-3

在VBA我目前使用类似于下面的代码来创建和发送Outlook邮件项目C#应用程序:发送的Outlook邮件项目从

Function example() 

Dim OutAppl As Outlook.Application 
Dim my_email As Outlook.MailItem 

Set OutAppl = New Outlook.Application 
Set my_email = OutAppl.CreateItem(olMailItem) 

    With my_email 

     .Importance = 2 
     .To = "[email protected]; " 
     .Subject = "not so easy in C#" 
     .BodyFormat = 2 'olFormatHTML 
     .HTMLBody = "<P>" & _ 
        "<BR>" & _ 
        "<FONT face=""Lucida Sans Unicode"" size=2.5>" & _ 
         "Hello SO" & _ 
         "<BR>" & _ 
         "</FONT>" & _ 
         "</P>" & _ 
        "</BODY></HTML>"   
     .Save 
     .send 
    End With 

Set OutAppl = Nothing 
Set my_email = Nothing 

End Function 

我在哪儿创建上面使用类似的开始C#? 有没有一个前瞻性的介绍我可以参考类似于使用excel?

+2

您是否必须使用Outlook?它可能更容易使用[System.Net.Mail](http://msdn.microsoft.com/en-us/library/dk1fb84h.aspx)。 – jrummell

+3

只需在Google中提出您的问题标题即可获得大量相关结果... – Servy

+1

您确切的要求是什么?有[Outlook互操作程序集](http://msdn.microsoft.com/en-us/library/office/bb652780.aspx),您可以使用,但正如jrummell所说:你真的需要使用它吗? – Default

回答

1

直接回答你的问题时,Outlook互操作库只有几个从擅长于Visual Studio的Add Reference对话框下来:

References

而且是它以同样的方式作为擅长的工作,你实例一个Outlook应用程序对象,然后可以通过Outlook中的VBA或多或少地执行任何操作,可以通过调用.Net中的应用程序实例等效方法来完成。

如果你想要我添加一些示例代码只是评论,我会,但正如jrummell说,为什么不只是使用System.Net.Mail

+1

感谢这篇文章(同意我应该在发布这个问题之前做了一点研究)根据'System.Net.Mail'是SMTP的一些东西存在于所有Exchange服务器上? – whytheq

+1

我不是Exchange服务器上的专家,但我会这样认为,您应该能够获得您的IT部门的这些职位,然后您将这些作为您的System.Net.Mail.SmtpClient对象的属性提供你可以设置一个像Outlook或Thunderbird这样的标准邮件客户端 – JMK

+1

http://systemnetmail.com/上有很多例子。 – jrummell