[Question] How does a bot send emails (in outlook)?
I'm new to the bot framework so please be kind :)
I was working on my bot and noticed that an email was sent from my outlook account with the same message that was in a certain statement in my code. Here is the statement:
await context.PostAsync("TODO: Finish this method");
I have registered the bot on the bot framework and did email as a channel, but I wasn't testing the bot in my email at all, (I was testing it in MS Teams). Is that what caused this to send an email from my account? I just want to make sure this doesn't happen again.
It may be relevant to mention I'm using LUIS intents and when I triggered this method's intent by entering input into MS Teams it ran this line of code, and then an email was sent? I'm thinking it had to do with adding my email as a channel on the bot framework but I want to make sure.
If it helps here is the full method:
[LuisIntent("Show Joke")]
public async Task displayJoke(IDialogContext context, LuisResult result)
{
await context.PostAsync($"TODO: Finish this method");
}
Thanks.
@meganlcooper For email channel, I recommend setting up a new outlook account that is used by your bot only.
As to what caused the email to send. It's hard to say without knowing exactly what code was running at the time. Sounds like you activated inadvertently during testing your code.
Keep in mind, when the bot is connected to the email channel + your personal email account, it could potentially start responding to every email sent to you. This is why I recommend creating a new email account for your bot, that way you know what messages are created by the bot. Also, would prevent false activation when you get regular (not intended for the bot) mail.
@nwhitmont Thanks for the help. I disconnected the bot from my email channel, I hope that fixes the issue
@nwhitmont Could you please send some sample code that sends out any email. I have enabled Email channel by creating new outlook account. Here is the code
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
if (activity.ChannelId != "email")
{
await Conversation.SendAsync(activity, () => new Dialogs.EmailDialog()); } } } public async Task StartAsync(IDialogContext context) { var message = context.Activity as IMessageActivity;
var reply = context.MakeMessage();
ChannelData data = new ChannelData();
data.htmlBody = "<html><body style='font-family: Calibri; font-size: 11pt;'>This is the email body!</body></html>";
data.subject = "This is the email subject";
data.importance = "high";
string json = JsonConvert.SerializeObject(data);
reply.ChannelData = json;
await context.PostAsync(reply);
// await fetchOrderDetails(context, query);
}
I am getting reply from bot but the problem is I am getting twice . One with actual message body Other with body saying Sorry, my bot code is having an issue.
@sridharbm1991
Is your issue resoved? I am facing same issue.
@PriyaB07 Not yet resolved 😞
@sridharbm1991 mine is working now, I tried setting reply.Text instead reply.ChannelData