How to make my bot send an e-mail to a given email address?

ⅰ亾dé卋堺 提交于 2021-02-11 18:21:17

问题


I am building a bot using Microsoft Bot Framework (.NET) and I want a Contact dialog where the user writes the subject, the body of the email and the user he wants to send the email to.

For example, imagine the bot user is asking questions, if the bot can not propperly answer the question, I would like to throw a contact dialog where the user can contact the administration to ask his/her question via e-mail.

As far as I know, I can integrate the email channel with a Office 365 email so my bot can answer e-mails. But is there a way to send emails? I am using a Direct Line API channel.

Thank you in advanced!


回答1:


Use SmptClient or SendGrid to send your email for example. There are many samples on StackOverflow, like the following: Send e-mail via SMTP using C#

Using the Email channel is not a good idea in this case: it will not manage the flow like you want, and is a misuse of the channel. Email channel is a channel like all the others, which must be used for a conversation, not to send a message at once for special needs.




回答2:


There is a way your bot to send emails. You should first use an Email service.In my case I use SendGrid. Code looks like that:

             System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
             SmtpClient SmtpServer = new SmtpClient("smtp.sendgrid.net");

             mail.From = new MailAddress("youremailaddress@gmail.com");
             mail.To.Add(useremail);
             mail.Subject = "";
             mail.Body ="";

             SmtpServer.Port = 587;
             SmtpServer.Credentials = new System.Net.NetworkCredential("apikey", "");
             SmtpServer.EnableSsl = true;

             SmtpServer.Send(mail);


来源:https://stackoverflow.com/questions/53847791/how-to-make-my-bot-send-an-e-mail-to-a-given-email-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!