C# Outlook Interop 从文件夹发送
我正在尝试从列为文件夹的电子邮件地址发送电子邮件。基本上我有一个分配有电子邮件地址的文件夹。每当该电子邮件有内容时,它就会进入文件夹。该电子邮件地址不是分配给我的帐户。我会使用 SMTP 但我们的公司网络不允许这样做。
如何从此文件夹的电子邮件中用 C# 发送电子邮件?
我的代码设置如下。
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon(Missing.Value, Missing.Value, true, true);
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.Subject = subject;
string html;
html = message;
html = html.Replace("\n","<br/>");
oMsg.HTMLBody = html;
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(to);
//Rest of my closing stuff here.
I'm attempting to send an email from a e-mail address that's listed as a folder. Basically I have a folder with an e-mail address assigned to it. Whenever something comes to that email it goes to the folder. The E-Mail Address is not an account assigned to me. I would use SMTP But our corporate network does not allow this.
How can I send an e-mail in C# from this Folder's E-Mail?
My code is setup as follows.
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon(Missing.Value, Missing.Value, true, true);
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.Subject = subject;
string html;
html = message;
html = html.Replace("\n","<br/>");
oMsg.HTMLBody = html;
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(to);
//Rest of my closing stuff here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已经拥有该文件夹的电子邮件地址(您没有提及这是否是问题的一部分,但听起来似乎不是),则不必为此使用 Outlook 互操作。尝试 System.Net.Mail 中的类。 这个网站有一些很好的例子,但这里有一些快速的东西:
我只是猜测我得到的部分收件人地址,它基于此 MSDN 页面。
If you already have the folder's email address (you don't mention if this is part of the problem but it sounds like it is not) you shouldn't have to use Outlook interop for this. Try the classes in
System.Net.Mail
. This site has some good examples, but here's something quick:I'm only guessing about the part where I get the recipient address, it's based on this MSDN page.
在我看来,整个文件夹的事情与你的问题无关(如果我错了,请纠正我),归根结底就是你想通过 Outlook 发送一封带有特定回复地址的电子邮件。您可以使用 MailItem.SenderEmailAddress该目的:
作为替代方案,您可以将回复地址添加到 MailItem.ReplyRecipients 集合。
Seems to me the whole folder thingy is irrelevant to your problem (correct me if I'm wrong there), and all it comes down to is you want to send an e-mail through Outlook with a specific reply address. You can use MailItem.SenderEmailAddress for that purpose:
As an alternative, you could add the reply address to the MailItem.ReplyRecipients collection.