I've got a big problem with Database Mail

  • I just discovered that the max body size of my email message is nvarchar(max), which limits my email content to 4000 characters. The problem is, I am building email content dynamically, and it can get pretty big and completely blow past 4000 characters.

    We have a C# front end that is actually putting together the emails currently, but we send a ton of information to the front end in multiple trips that has to be pieced together there and I wanted to do it all at once by putting all of the process on the database.

    I've given a brief thought to modifying sp_send_dbmail to allow a larger string, but wasn't sure what would happen beyond passing it there if I did. Has anyone done this before?

  • Okay, I've looked into sp_send_dbmail further and can see I send the vaule of @body into sysmail_mailitems which is also [body] [nvarchar](max) NULL, so I know I would have to modify this. . .

  • Okay, this is about as far as I can go. I am not sure what happens next, or what the impact would be on the email side if I edited this column. Anyone have any ideas?

  • Why do you think a max body size of nvarchar(max) limits your email content to 4000 characters?

    Have you run a test to see if it is actually limited to 4000 characters?

    Have you looked up the definition of nvarchar(max) in SQL Server 2005 Books Online?

  • as I understand it nvarchar is for unicode, so each character will take up 2 bytes. so rather than having about 8000 characters for a varchar, I've got about 4000 for nvarchar.

  • nevermind, just read up on it again. Looks like it will do.

  • Please review this topic in BOL as was suggested earlier. From BOL:

    nvarchar [ ( n | max ) ]

    Variable-length Unicode character data. n can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. The SQL-2003 synonyms for nvarchar are national char varying and national character varying.

    Jeff

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply