I need to send an attachment user is sending from bot framework emulator to a mail id via smtp server. I am successful at retrieving the attachment from user, but the same attachment is not getting transferred via smtp mail.
The time of attachment received from the bot is of type Microsoft.Bot. Connector.Attachments but smtp attachment needs to be in the type System.Net.Mail.Attachment.
I have tried the answers from this link :- Ability to receive files with the MS bot framework.
But this did not solve my problem completely.
I have tried the conversion by using the Name value of Bot attachment.
MailMessage message = new MailMessage(EntityValues.FromEmail, To, Subject, MessageBody);
if (attachment != null)
{
System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(attachment.Name);
message.Attachments.Add(data);
public virtual async Task SaveAttachment(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
if (message.Attachments != null && message.Attachments.Any())
{
var attachment = message.Attachments.First();
string sendresult = SendEmail(EntityValues.ToEmail, EntityValues.ProblemHeader, EntityValues.problemStatement,attachment);
I passed the attachment and then tried to add the name of attachment on message as below:
public string SendEmail(string To, string Subject, string MessageBody, Microsoft.Bot.Connector.Attachment attachment)
{
try
{
MailMessage message = new MailMessage(EntityValues.FromEmail, To, Subject, MessageBody);
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.Default;
if (attachment != null)
{
System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(attachment.Name);
message.Attachments.Add(data);
But I am getting the below error message:
System.IO.FileNotFoundException: Could not find file ‘C:\Program Files (x86)\IIS Express\colorado-sunrise.jpg’ jpg’. File name: ‘C:\Program Files (x86)\IIS Express\colorado-sunrise.jpg’ at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType) at System.Net.Mail.AttachmentBase..ctor(String fileName) at System.Net.Mail.Attachment..ctor(String fileName) at MyBotApp.StateDialogTest.SendEmail(String To, String Subject, String MessageBody, Attachment attachment) in ..
Please help.
Could not find file ‘C:\Program Files (x86)\IIS Express\colorado-sunrise.jpg’
pretty much says it all. – bashis