У меня есть бот, созданный в framework v4 с использованием c#. Бот отправляет электронное письмо администратору, если не может получить ответ от qna maker. Он полностью работает на локальном эмуляторе, я могу отправить письмо, но когда публикуется через слабину, бот выдает ошибку. Вот частный код asyn c Task ProcessSampleQnAAsyn c (WaterfallStepContext stepContext, CancellationToken cancellationToken) {
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);
}
}
appsetting. json
"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.
Общий лог c smtp
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;
}}