尝试连接到“ smtp.office365.com”时出现MailKit.Security.SslHandshakeException

时间:2019-03-21 19:08:05

标签: c# email ssl mailkit

我正在尝试使用MailKit通过“ smtp.office365.com”发送电子邮件。这是我正在使用的代码。

sp <- split(data1_melt, data1_melt$x)
sp <- lapply(sp, function(DF) {
  i <- !duplicated(DF[["y"]])
  DF[i, ]
})

data1_melt <- do.call(rbind, sp)
rm(sp)

ggplot(data1_melt, aes(x = x, y = y, z = pr)) +
  geom_contour()

我从GitHub上的this comment获得的 #include <iostream> #include <cstdlib> using namespace std; int shoppingList (int &money, int &userChoice) { cout<<"\n\n\n\n\n\n"; cout<<"\t\t\t\t\t\t\t1. Apples for 20$"; cout<<"\t\t\t\t\t\t\t2. Oranges for 30$"; cout<<"\t\t\t\t\t\t\t\n\nChoice: "; cin>>userChoice; if (userChoice == 1) { money = money - 20; cout<<"20$ has deducted "<<endl; } if (userChoice == 2) { money = money - 30; cout<<"30$ has deducted "<<endl; } } int main() { int userChoice; int money = 500; while (true) { char choices[2]; cout<<"\n\n\n\n\n\n"; cout<<"\t\t\t\t\t\t\t"<<"Money: "<<"$"<<money<<"\n\n" <<endl; cout<<"\t\t\t\t\t\t\t1. Shop"; cout<<"\t\t\t\t\t\t\t\n2. Exit"; cout<<"\t\t\t\t\t\t\t\n\nChoice: "; cin>>choices; if (choices[0] == '1') { system ("CLS"); shoppingList (money ,userChoice); system ("PAUSE"); system ("CLS"); } else if (choices[0] == '2') { return 0; } else if (choices[0] > '2' || choices[0] < '1') { cout<<"\nInvalid Input\nPLs try again"<<endl; system ("PAUSE"); system ("CLS"); } else { cout<<"\nInvalid Input\nPLs try again"<<endl; system ("PAUSE"); system ("CLS"); } } } 类。

每当我运行此代码时,我都会得到一个using (var client = new SmtpClient(new ProtocolLogger("smtp.log"))) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("smtp.office365.com", 587, SecureSocketOptions.SslOnConnect); client.Authenticate(new SaslMechanismNtlmIntegrated()); Debug.WriteLine(client.IsAuthenticated); client.Send(message); client.Disconnect(true); }

以下是该例外的详细信息:

SaslMechanismNtlmIntegrated

我去了细节中提到的FAQ,但是给出的解决方法无法解决问题。

1 个答案:

答案 0 :(得分:3)

willaien提到的解决方案解决了此问题。即,使用SecureSocketOptions.StartTls代替SecureSocketOptions.SslOnConnect