C# 无法从与slack集成的bot发送邮件
我在framework v4中使用c#制作了一个bot。如果bot无法从qna maker获取答案,它会向管理员发送一封电子邮件。它在本地模拟器上完全正常工作,我可以发送邮件,但在发布时,由于时间过长,bot会抛出一个错误。 这是代码 专用异步任务进程SampleQNAAsync(WaterWallStepContext stepContext,CancellationToken CancellationToken) {C# 无法从与slack集成的bot发送邮件,c#,asp.net-core,smtp,botframework,slack,C#,Asp.net Core,Smtp,Botframework,Slack,我在framework v4中使用c#制作了一个bot。如果bot无法从qna maker获取答案,它会向管理员发送一封电子邮件。它在本地模拟器上完全正常工作,我可以发送邮件,但在发布时,由于时间过长,bot会抛出一个错误。 这是代码 专用异步任务进程SampleQNAAsync(WaterWallStepContext stepContext,CancellationToken CancellationToken) { var results = await _botServi
var results = await _botServices.SampleQnA.GetAnswersAsync(stepContext.Context);
if (results.Any())
{
await stepContext.Context.SendActivityAsync(MessageFactory.Text(results.First().Answer), cancellationToken);
}
else
{
var question = stepContext.Context.Activity.Text;
await stepContext.Context.SendActivityAsync(MessageFactory.Text(_configuration["DefaultAnswer"]), cancellationToken);
string mailbody = "<h4><b>Hi Admin , following question was not answered from bot : </b> </h4>" + question;
Common objCommon = new Common(_configuration);
objCommon.SendEmail(_configuration["EmailSubject_UnAnswerQuestion"], mailbody);
}
}
smtp的通用逻辑
请包括您收到的错误。@mdrichardson-MSFT,,,,它显示在slack上机器人有错误,请修复它,您需要更具体一些。slack中显示了什么错误?机器人的控制台日志中显示了什么错误?我几乎没有足够的信息来开始提出修复建议。请进行一些调试并告诉我你尽可能多地告诉我这个错误。如果你可以的话,这将是非常有帮助的
"AdminEmailAddress": "****@****.com", //to Email Address
"FromEmailAddress": "******@gmail.com", // From email address
"SMTP_Host": "smtp.gmail.com", // SMTP client Host Name
"SMTP_Port": "587", // SMTP port number
"SMTP_UserName": "****@gmail.com", // email server user name (Email server
network credentials)
"SMTP_Password": "******", // email server password (Email server network
credentials)
"EmailSubject_UnAnswerQuestion": "Question whose answer not found", //
Subject string for un- answere question email.
"DefaultAnswer": "Sorry, could not find an answer in the Q and A system.", //
default answere if answere not found in QnA.
"DelayTimeInSeconds": "60" // Feed back dely time in seconds.
public class Common
{
private readonly IConfiguration _configuration;
public Common(IConfiguration configuration)
{
_configuration = configuration;
}
public bool SendEmail(string subject, string mailbody)
{
string to = _configuration["AdminEmailAddress"]; //To address
string from = _configuration["FromEmailAddress"]; //From address
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.Body = mailbody;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient(_configuration["SMTP_Host"],
int.Parse(_configuration["SMTP_Port"])); //Gmail smtp
System.Net.NetworkCredential basicCredential1 = new
System.Net.NetworkCredential(_configuration["SMTP_UserName"],
_configuration["SMTP_Password"]);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicCredential1;
try
{
client.Send(message);
return true;
}catch (Exception ex)
{
throw ex;
}}