dineshkummarc / sendgrid-csharp

i liked the project to such an extent i also copied their issues to be solved. so as i can work on them.
MIT License
0 stars 0 forks source link

Can't add inline Images on HTML Emails (solution here) #6

Open dineshkummarc opened 11 years ago

dineshkummarc commented 11 years ago

When sending an HTML email with inlineImages, you can't....

The following code exposes enough in the SendGrid.cs class to work for my needs (ability to include file streams rather than just the Filenames would probably be handy)

There are more elegant solutions, but this one works in a pinch.

---------------Add to SendGrid.cs (in Mail project)------------

public struct inlineImage
{
    public inlineImage(string _FileName, string _Cid)
    {
        FileName = _FileName;
        Cid = _Cid;
    }

    public string FileName;
    public string Cid;
}

public List<inlineImage> htmlInlineImages = new List<inlineImage> { };

-----------Modify CreateMimeMessage's if (Html != null) block------------

    if (Html != null)
    {
        AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Html, null, "text/html");
        foreach (inlineImage X in htmlInlineImages)
        {
            LinkedResource imageResource = new LinkedResource(X.FileName);
            imageResource.ContentId = X.Cid;
            htmlView.LinkedResources.Add(imageResource);
        }

        message.AlternateViews.Add(htmlView);
    }