Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Download and attach file into Email from Azure blob storage

Posted on by 39

Hi all,

I have attached Product image into Azure blob, i need to attach the uploaded image into Email and send to my customers. i tried to get the image using DocuValue and DocuRef tables but i can't able to download and attach them in the Email.

when i use the same path in Email template, the image is not getting displayed in both draft email and received Email.

kindly suggest me an option to achieve this.

  • BINAY KUMAR PANDEY Profile Picture
    BINAY KUMAR PANDEY 135 on at
    RE: Download and attach file into Email from Azure blob storage

    Hi ,

    Can you please provide the full code , I have to do the same thing , I am not understanding here waht is build here ? Please provide the full code which worked for you .

  • Suggested answer
    Whites Road Profile Picture
    Whites Road 39 on at
    RE: Download and attach file into Email from Azure blob storage

    I did something else to attach the image from azure blob (which got stored from attachments to blob),  i have used the below codes to attach the image to Email.

    fileStream =  DocumentManagement::getAttachmentStream(docuRef);

    builder.setFrom("d365admin@test.com");

    builder.addTo("d365admin@test.com");

    builder.setSubject("attachment");

    builder.setBody("Test email");

    builder.addAttachment(fileStream,docuValue.FileName);

    this helped to solve my issue. Thanks for the support

  • Whites Road Profile Picture
    Whites Road 39 on at
    RE: Download and attach file into Email from Azure blob storage

    Thanks for the reply  Kokulan Eswaranathan.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Download and attach file into Email from Azure blob storage

    You will have to first get the image from Blob, a sample code from this link :

    https://community.dynamics.com/365/b/heralddyncrm/archive/2018/05/27/upload-and-download-files-in-azure-blob-using-c 

    var containerName = "testcontainerherbi";

    string storageConnection = CloudConfigurationManager.GetSetting("BlobStorageConnectionString"); CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(storageConnection); CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();

    CloudBlobContainer cloudBlobContainer = blobClient.GetContainerReference(containerName); CloudBlockBlob blockBlob = cloudBlobContainer.GetBlockBlobReference("uploadedfilename.ext");

    MemoryStream memStream = new MemoryStream();

    blockBlob.DownloadToStream(memStream);

    You can convert the Memory Stream to Byte Array and use the following sample to create attachment for Email

    ActivityMimeAttachment _sampleAttachment = new ActivityMimeAttachment
    {
    ObjectId = new EntityReference(Email.EntityLogicalName, _emailId),
    ObjectTypeCode = Email.EntityLogicalName,
    Subject = String.Format("Sample Attachment {0}", i),
    Body = System.Convert.ToBase64String(Your Byte Array),
    FileName = String.Format("ExampleAttachment{0}.txt", i)
    };

  • Whites Road Profile Picture
    Whites Road 39 on at
    RE: Download and attach file into Email from Azure blob storage

    i am working with D365 F&O, where i am adding the image using attachment option in the product master.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans