在 C# 中使用 Outlook 对象发送电子邮件时更改发件人的电子邮件地址和姓名
过去两天我一直在努力解决这个问题。我觉得我真的很接近,但就是无法得到。我已经让我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我确实相信,因为您使用的是 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.
如果您使用 Interop.Outlook.dll,最好从服务器更改配置文件名称
Better change the profile name from server if you are using Interop.Outlook.dll