+2 votes

Hello,

I want to set size of Mail to 10 MB. So, user can not add attachments >10 MB.
I want to popup message if size of the mail exceeds 10 MB.

Please review following code and suggest me how to achieve it.

using (Smtp smtp = new Smtp())
{
    //Add all the information to builder
    MailBuilder builder = new MailBuilder();
    foreach (var item in filesCollection)
    {
        if (!item.Value.FullFileName.Contains(".vcs"))
            builder.AddAttachment(item.Value.FullFileName.Trim());
    }
    IMail email = builder.Create();

    SendMessageResult result = smtp.SendMessage(email);
}

1- How can I achieve above goal?
2- Also let me know what is Maximum size I can attached with mail?
3- Is there any limitation regarding to size in demo version of Mail.dll?
Please suggest.

by (3.0k points)
edited by

1 Answer

+1 vote

So, user can not add attachments >10 MB.

You can check the file size using FileInfo class:

long fileSize = new FileInfo(fileName).Length;

Please note that Base64 encoding, that email usually uses, makes all attachments ~37% bigger during transport

37% is the result of the MIME's 76 chars per line limitation, causing \r\n to be added every 76 chars.

I want to popup message if size of the mail exceeds 10 MB.

You can use IMail.Render() to get the raw bytes of the message. Length of the array is the actual email size.

Depending on your requirements it may be easier to sum actual attachment sizes (multiplied by 1.37 for Base64, XUUE and UUE encoded attachments: MimeData.ContentTransferEncoding)

2- Also let me know what is Maximum size I can attached with mail?

There is no limit, however please have in mind that base64 encoding that email uses makes all attachments 33% bigger.

3- Is there any limitation regarding to size in demo version of
Mail.dll?

There is no such limitation.

by (301k points)
Thank you.

How can I get Actual email size?
I have tried by IMail.Render() but there is no method like Render().
There is method availble RenderEml() which has return type String.

How can I calculate this?
I am using Visual Studio 2013.
Please update the component to the latest version:
https://www.limilabs.com/mail/download
...