在 C# 中使用 Outlook 对象发送电子邮件时更改发件人的电子邮件地址和姓名

发布于 2024-12-07 23:34:22 字数 795 浏览 0 评论 0原文

过去两天我一直在努力解决这个问题。我觉得我真的很接近,但就是无法得到。我已经让我的 c# 程序成功发送了一封包含所有必需信息的电子邮件,但我无法更改发件人的姓名和电子邮件地址。到目前为止,这是我的代码:

Outlook.Application oApp = new Outlook.Application();

string emailrecipient = (Convert.ToString(txtAdmin1.Text) + "@domain.com");


            Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
            email.Recipients.Add(emailrecipient);
            email.Subject = "Your Recent Admin Rights Request";
            email.Body = "Your admin rights request has been processed. The user " + txtAdmin1.Text + " has been added as an administrator on computer " + txtName.Text + ". Please reboot your computer for these changes to take effect.";

            email.Send();

任何建议都会很棒。我已经到处寻找,但到目前为止还没有找到任何有效的方法。

I have been trying to figure this one out for the last 2 days. I feel like I'm really close, but just can't get it. I've gotten my c# program to successfully send an email with all the required information in it, but I can't change the sender's name and email address. Here is my code so far:

Outlook.Application oApp = new Outlook.Application();

string emailrecipient = (Convert.ToString(txtAdmin1.Text) + "@domain.com");


            Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
            email.Recipients.Add(emailrecipient);
            email.Subject = "Your Recent Admin Rights Request";
            email.Body = "Your admin rights request has been processed. The user " + txtAdmin1.Text + " has been added as an administrator on computer " + txtName.Text + ". Please reboot your computer for these changes to take effect.";

            email.Send();

any advice would be amazing. I've searched all over the place, and haven't found anything that has worked so far.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掩耳倾听 2024-12-14 23:34:22

我确实相信,因为您使用的是 Outlook 对象模型,所以 From 属性是只读的(我认为它称为 SenderName / SenderEmailAddress)。

Outlook 在特定用户的上下文中运行,因此要更改用户,您必须使用不同的凭据登录 Outlook。

I do believe that because you are using the Outlook object model, the From property is read only (i think its called SenderName / SenderEmailAddress).

Outlook runs in the context of a specific user, so to change the user you would have to login to outlook using different credentials.

话少心凉 2024-12-14 23:34:22

如果您使用 Interop.Outlook.dll,最好从服务器更改配置文件名称

Better change the profile name from server if you are using Interop.Outlook.dll

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文