0

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!

Marisa
  • 1,135
  • 3
  • 20
  • 33

2 Answers2

2

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.

Nicolas R
  • 13,812
  • 2
  • 28
  • 57
  • So I should implement this function inside my bot to send the e-mail/message using the Direct Line API channel instead of creating an Email channel, right? – Marisa Dec 19 '18 at 12:41
  • Yes. In your bot code, just add the code to send the email where you need it (so in your contact Dialog here), and that's all you need – Nicolas R Dec 19 '18 at 12:43
  • Ok. And what if instead of sending an e-mail I would like to send a message to the app where the direct line api is hosted? Could the same or something similar work? – Marisa Dec 19 '18 at 12:49
  • I can't answer that, without knowing more details. What kind of "app" are you talking about, how do you send message to this app, etc. – Nicolas R Dec 19 '18 at 12:53
1

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);
DimosD
  • 51
  • 2