Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello. I have the following code:

 

 Dim mail As New MailMessage(email_from, email_address, Subject, body)

       If EmailBCC <> "" Then mail.Bcc.Add(EmailBCC)

       Dim client As New SmtpClient(email_smtp)
       client.UseDefaultCredentials = False
       client.Credentials = New Net.NetworkCredential(email_user, email_pass)
       client.DeliveryMethod = SmtpDeliveryMethod.Network
       mail.IsBodyHtml = True

       If CuAtasament = True Then
           mail.Attachments.Add(New Attachment(pdf_stream, "Factura " & NrFactura & " - " & Utilizator & ".pdf"))
       End If


       Dim dac As New DataAccess


       Try
           client.Send(mail) 

           Call pdf_stream.Dispose()
           Call mail.Dispose()


           Return True 'Succes

       Catch ex As Exception

 

Problem is RAM is loading up, and if i have 3000 emails to send, eventually it will crash. Any ideeas on how to clear data from memory?

Development & Research Department @ Elven Soft
  • Administrators
Posted

Are you getting any exceptions raised in your code? If so there is a chance the two .Dispose calls at the end of your post are not being called. You might want to move them into a Finally block

 

e.g.

Try
   client.Send(mail) 
   Return True 'Succes
Catch ex As Exception
   'rest of error handler
Finally
   pdf_stream.Dispose()
   mail.Dispose()
End Try

and see if that makes a difference.

 

You may also find that creating a single instance of the SmtpClient and using for all the mail rather than creating a new one per e-mail might keep the overheads down.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...