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.
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 .
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
Thanks for the reply Kokulan Eswaranathan.
You will have to first get the image from Blob, a sample code from this link :
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)
};
i am working with D365 F&O, where i am adding the image using attachment option in the product master.