Graphics in an Email

Hi,

I want to send an Email from Aras, but with some graphics included. It would typically be a bitmap or svg from the vault.

.....My guess would be that one would use C# to first copy the picture to somewhere on the server.

But can one include a reference to a resource in the mail template? If so, what root directory will it be using as reference?

Kind Regards

Riaan

  • Do you want to add the picture as attachment or as inline image? For inline images you could convert your image to a base64 string that you then can add as regular email content. But in reality these images will often be blocked by email programs.

  • Hi Riaan,

    I don't think it is possible to include attachments in the Aras mail templates, unfortunately.
    So you would have to send the Email form a server method using, for example, the MailMessage, Attachment and SmtpClient classes in System.Net.Mail.
    If you had hoped to simply include the svg in the HTML (a reasonable hope), that is not widely supported. So you would have to add the image as an attachment to the email and then reference that attachment in the HTML using its content ID (cid). Here's an example of what such an Aras method could look like (obviously the settings would have to be adjusted for your setup, SMTP server and security requirements):

    const string toEmailAddress = "[email protected]";
    const string fromEmailAddress = "[email protected]";

    const string contentId = "myImageId";

    var message = new System.Net.Mail.MailMessage(fromEmailAddress, toEmailAddress)
    {
       Subject = "An Email Subject",
       Body = $"<html><body>This is an <img src=\"cid:{contentId}\" /> embedded image.</body></html>",
       IsBodyHtml = true
    };

    var attachment =
       new System.Net.Mail.Attachment(@"PathToSomeFolderOnServerWithSomeImage\SomeImage.jpg")
       {
         ContentId = contentId
       };
    message.Attachments.Add(attachment);

    var client = new System.Net.Mail.SmtpClient
    {
       Host = "smtp.server.com", 
       Port = 123,       
       UseDefaultCredentials = true,
       EnableSsl = true,   
       Credentials = new NetworkCredential("[email protected]", "passwordForThatUser")
    };

    client.Send(message);

    return this;

    Hope this helps,

    C

  • Thanks Angela, I had inline in mind. I will investigate the base64 option, but the blocking of images is something to take note off.

  • Thanks C, I did expect at least svg compatibility.  But I did not know about the cid possibility. I will investigate....