我的ChatBot中有一个LUIS意图,以用户身份发送电子邮件(以下代码)。此刻,它像我一样向我发送电子邮件(但从具有允许从每个人的邮箱发送权限的自动化邮箱发送)。我希望它读取与MS Teams中的机器人进行交互的用户的属性,并改用该用户的电子邮件地址吗?
[LuisIntent("Endpoint_CreateTicket")]
public async Task EndpointCreateTicketIntent(IDialogContext context, LuisResult result)
{
using (SmtpClient client = new SmtpClient())
{
using (MailMessage message = new MailMessage())
{
client.Host = "smtp.office365.com";
client.Port = 587;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("<confidential>", "<confidential>");
client.EnableSsl = true;
message.From = new MailAddress("Mark.Hawkins-Wood@christie.com");
message.Subject = "THIS IS THE SUBJECT";
message.Body = "THIS IS THE BODY";
message.To.Add("Mark.Hawkins-Wood@christie.com");
try
{
client.Send(message);
}
catch(Exception e)
{
await context.PostAsync(e.Message);
}
}
}
}
答案 0 :(得分:1)
您应该有一个提取电子邮件的意图。例如,您可以有一个名为ExtractEmail
的类型Email
用户可以输入类似my email is klex@outlook.com
,
因此,您的LUIS JSON响应返回类似
"entities": [
{
"entity": "klex@outlook.com",
"type": "Email",
"startIndex": 18,
"endIndex": 22,
"score": 0.9866132
}]
从您的功能中尝试
using System.Net.Mail;
try{
MailAddress mail = new MailAddress(result.entity);
message.From = mail;
}
catch(Exception){
//Reply with an error
}