c# - 从没有 SMTP 服务器的共享电子邮件地址发送电子邮件
问题描述
我想以编程方式使用给定的共享邮箱名称发送电子邮件。我无权访问 smtp 服务器,因此无法使用 System.Net.Mail。
我正在使用 Outlook = Microsoft.Office.Interop.Outlook
;
如何从共享邮箱电子邮件而不是默认电子邮件地址发送?
outlook.MailItem mail application.CreateItem(outlook.OlItemType.olMailItem) as outlook.MailItem;
try
{
if (mail.Subject.Contains("Highway Alert")
{
mail.SendUsingAccount = "sharedmailboxemail@email.com"
mail.Send();
System.Diagnostics.Debug.WriteLine("Email Sent ");
}
else
解决方案
MailItem.SendUsingAccount属性返回或设置一个Account对象,该对象表示要在其下MailItem
发送邮件的帐户。例如:
private void SendUsingAccountExample()
{
Outlook.MailItem mail = Application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.Subject = "Our itinerary";
mail.Attachments.Add(@"c:\travel\itinerary.doc", Outlook.OlAttachmentType.olByValue,
Type.Missing, Type.Missing);
Outlook.Account account = Application.Session.Accounts["Hotmail"];
mail.SendUsingAccount = account;
mail.Send();
}
有关详细信息,请参阅使用 Hotmail 帐户发送邮件项目。
请记住,在这种情况下,应在 Outlook 中配置另一个帐户。
SentOnBehalfOfName属性仅在 Exchange 配置文件/帐户的情况下才有意义。此外,您需要具有代表他人发送所需的权限。有关类似讨论, 请参阅SentOnBehalfOfName问题。
如果您在配置文件中配置了多个帐户,则可以使用SendUsingAccount属性,该属性允许 Account 对象表示要发送 MailItem 的帐户。
Sub SendUsingAccount()
Dim oAccount As Outlook.account
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
oMail.Recipients.Add ("someone@example.com")
oMail.Recipients.ResolveAll
oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub
推荐阅读
- javascript - 在应用程序和 Node 中使用 ES6 模块,同时使用 Webpack-Dev-Middleware 和 Express
- .htaccess - 有没有办法在不更改网址的情况下进行重定向?
- javascript - 使用 React 进行身份验证后如何重定向到不同的页面
- safari - Safari CORS 问题 - Access-Control-Allow-Origin 不允许主机
- javascript - Javascript 展开数组/更改数据结构
- icloud - CloudKit“部署到生产”不显示记录更改,“部署”灰显
- ruby-on-rails - 使用 STI,临时子类的第一次读取失败,但后续读取工作
- python - (1) 处的外部函数“f”在带有 f2py 的子程序中没有隐式类型
- mysql - MySQL - 使用子查询优化查询
- android - 在 Android Studio 中获取红色类且没有语法错误