0 votes

Hi
I would like to loop through all files in a windows folder and use "email template Engine" to present thoose files in a nice look and send it as an email.
Is this possible and how would I do that?

Best regards
Johnny

by
Hi By "nice look" i mean the same look that you have in the example for email template.


The mail should look like this

Hi Mr. xxxxx

here are all the files located in folder c:\temp\

filname_xxxxx.PDF
Filname_xxxx2.TIF
Filename_xxx3.PDF

Best regards
Mr X

1 Answer

0 votes

You must be a little more specific. For example: what do you mean by "nice look" exactly?

To loop through files use Directory.GetFiles:

foreach (string fileName in Directory.GetFiles(@"c:\\"))
{

}

To learn more about how email template engine works you can read this article:
https://www.limilabs.com/blog/email-template-engine

Here's the small sample:

Contact data = ...;

 string html = Template
     .FromFile("template.txt")
     .DataFrom(data)
     .Render();

If you want to send an email with attachments use MailBuilder's AddAttachment method:
https://www.limilabs.com/blog/send-email-with-attachment

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("alice@mail.com", "Alice"));
builder.To.Add(new MailBox("bob@mail.com", "Bob"));
builder.Subject = "Test";
builder.Text = "This is a plain text message.";
builder.AddAttachment(@"../image.jpg");
by (300k points)
...