Login exception question

0 votes
asked Mar 3, 2010 by Lisa Robinson (120 points)
edited Mar 23, 2011

I'm getting a System.OutOfMemoryException when I do a Login command on my smtp client. Why would this happen?

Applies to: Rebex Secure Mail
commented Mar 3, 2010 by Martin Vobr (12,940 points)
It looks strange. Could you please edit your question and include more details such as 1) full exception including the stack trace (you can get it be calling the exception.ToString()). 2) SMTP communication log produced using a LogWriter property as described at http://www.rebex.net/kb/logging.aspx ?
commented May 21, 2010 by Lukas Pokorny (104,290 points)
It turned out the attachments you were using were truly massive (like 1GB). Because attachment data was kept in memory, this caused OutOfMemoryException.

1 Answer

0 votes
answered May 21, 2010 by Lukas Pokorny (104,290 points)
edited May 21, 2010

It turned out the attachments you were using were truly massive (like 1GB). Because attachment data was kept in memory, this caused OutOfMemoryException sooner or later.

Since Rebex Mail 1.0.3793.0, it is possible to save or send mail messages with attachments of unlimited length using the following code:

// create an e-mail
MailMessage mail = new MailMessage();
...

Attachment attachment = new Attachment();
attachment.Options |= MimeOptions.DoNotPreloadAttachments; // <-- this is new
attachment.SetContentFromFile(attachmentPath);
mail.Attachments.Add(attachment);

// save the e-mail
mail.Save(path);

// send the e-mail
Smtp smtp = new Smtp();
smtp.Connect("server01");
smtp.Options |= SmtpOptions.SendWithNoBuffer; // <-- this is new
smtp.Send(mail);

At the moment, this doesn't work when the e-mail needs to be signed or encrypted – in that case, the content is still read into memory.

...