好的,正如你上面看到的,我試圖通過運行的Outlook實例發送郵件。儘管我不能在沒有評論框的情況下發布代碼,但是沒有拉出我的頭髮@amitapollo給了我使用System.Net.Mail命名空間的線索。在一天結束的時候,我得到了它的工作。以下是我的代碼:
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient("myExchangeServerIPAddress");
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("myDomain\\myUsername", "myPassword");
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
System.Security.Cryptography.X509Certificates.X509Store xStore = new System.Security.Cryptography.X509Certificates.X509Store();
System.Security.Cryptography.X509Certificates.OpenFlags xFlag = System.Security.Cryptography.X509Certificates.OpenFlags.ReadOnly;
xStore.Open(xFlag);
System.Security.Cryptography.X509Certificates.X509Certificate2Collection xCertCollection = xStore.Certificates;
System.Security.Cryptography.X509Certificates.X509Certificate xCert = new System.Security.Cryptography.X509Certificates.X509Certificate();
foreach (System.Security.Cryptography.X509Certificates.X509Certificate _Cert in xCertCollection)
{
if (_Cert.Subject.Contains("[email protected]"))
{
xCert = _Cert;
}
}
smtpClient.ClientCertificates.Add(xCert);
//I was having problems with the remote certificate no being validated so I had to override all security settings with this line of code...
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; };
smtpClient.Send("[email protected]", "[email protected]", "mySubject", "myBody");
SMTPClient的外觀如何。特別向我們展示了client.UseDefaultCredentials,client.Credentials和client.DeliveryMethod的一般構造。是DeliveryMethod SmtpDeliveryMethod.Network?需要一些代碼。 – ApolloSoftware
感謝您的快速回復,@AmitApollo。 Outlook.Application myOutlook = new Outlook.Application(); Outlook.MailItem mailMessage =(Outlook.MailItem)myOutlook.CreateItem(Outlook.OlItemType.olMailItem); Outlook.NameSpace olNameSpace = myOutlook.GetNamespace(「MAPI」); Outlook.Accounts olAccounts = olNameSpace.Accounts; Outlook.Account myAccount = new Outlook.Account(); (olAccounts中的Outlook.Account olAccount){if(olAccount.SmtpAddress ==「[email protected]」){myAccount = olAccount; }} – user2320861
我似乎在這個評論框中格式化代碼時遇到了問題......我幾乎沒有發佈就做了回車。無論如何,我會繼續挖掘。 – user2320861