The code below should help. It uses Mail.dll email template engine and MeilBuilder class to create an email with rendered template and attachments:
public class AttchmentInfo
{
public string FullPath;
public string Name => Path.GetFileNameWithoutExtension(FullPath);
public string Extension => Path.GetExtension(FullPath);
}
public class TemplateData
{
public List<AttchmentInfo> Attachments;
};
[Test]
public void Method_Condition_Result()
{
string template = @"<table>
[foreach Attachments]
<tr>
<td>[Name]</td>
<td>[Extension]</td>
</tr>
[end]
</table>";
TemplateData templateData = new TemplateData
{
Attachments = new List<AttchmentInfo>
{
new AttchmentInfo {FullPath = "c:\\Test.pdf"},
new AttchmentInfo {FullPath = "c:\\Test2.pdf"},
}
};
string rendered = Template.Create(template)
.DataFrom(data)
.Render();
var builder = new MailBuilder();
builder.Subject = "Subject";
builder.From.Add(new MailBox("from@example.com"));
builder.To.Add(new MailBox("from@example.com"));
builder.Html = rendered;
foreach (var info in templateData.Attachments)
{
builder.AddAttachment(info.FullPath);
}
IMail mail = builder.Create();
}