Friday 8 October 2010

How to set email attachment max size



I think there are many ways to achieve that setting, two of those methods which I am aware of at this moment are:

1. Add this in the first part of your exim.conf file

message_size_limit = 10M

AFAIK this setting would restrict incoming as well as outgoing at 10MB.

2. If you want to restrict size of message per domain basis, you could follow the given steps as below:

:CAUTION: The following solution has NOT BEEN TESTED in a real environment

a. Create a file to store the size limits for each domain that you wish to limit the message size. Use wildcard (*) for limiting the message size for all the domains not contained in the file.

Code:

root@srv [~]# cat > /etc/mail/msg-size-limits
domain1.tld: 10M
domain2.tld: 20M
*: 5M


As per the above, we are restricting domain1 at 10MB, domain2 at 20MB and all other domains at 5MB

b. Create another file and store the messages which should return to the sender of the large message.

Code:

root@srv [~]# cat > /etc/mail/msg-size-limit-messages
domain2.tld: You are trying to send a message which is $message_size
in size. This is larger than your maximum message size limit
of ${expand:${lookup{$domain}lsearch*@{/etc/mail/msg-size-limits}}}.
*: The largest acceptable message size for $domain is
${expand:${lookup{$domain}lsearch*@{/etc/mail/msg-size-limits}}}.
Your message size was $message_size. Please revise your message so it
does not exceed this maximum file size and resend. If this is not
possible, contact the recipient in another way.


Note that domain names contained in first file maybe omitted in the second file and vice-versa. The omitted domains will be taken care by the wildcard (*) entry.

c. Add the following code in the Routers section of your Exim configuration file.
(Please note that ORDER in which you place your routers in this section DOES matter and that is exactly what needs to be tested practically and thoroughly even). I think it will go in the 7th box in the WHM editor of Exim config file.

Code:

large_messages:
driver = redirect
domains = +local_domains :
+relay_domains
condition = ${if >{$message_size}{${expand:${lookup{$domain}lsearch*@{/etc/mail/msg-size-limits}}}} {yes}{no}}
data = :fail:
${expand:${lookup{$domain}lsearch*@{/etc/mail/msg-size-limit-messages}}}


Hope that works 



No comments:

Post a Comment