从没有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
d21qgu9p 回答:从没有SMTP服务器的共享电子邮件地址发送电子邮件

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();
}

有关更多信息,请参见Send a mail item by using a Hotmail account

请记住,在这种情况下,应在Outlook中配置另一个帐户。

SentOnBehalfOfName属性仅在Exchange配置文件/帐户的情况下才有意义。此外,您需要具有所需的权限才能代表他人发送。有关类似的讨论,请参见Issue with 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 
本文链接:https://www.f2er.com/3157348.html

大家都在问