Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Email only sends after the program is closed.

Posted on 2011-09-30
1
Medium Priority
?
243 Views
Last Modified: 2012-05-12
The attached code is called froma loop to send email to patrons when they have mail.  There are two ways to it to send depending on how it is setup.  When using network authentication it sends all the emails except the last one, it only sends the last one when the software is closed.  not using network authentication non of the emails are sent until the program is closed.  The only time an error is generated is if it is being debugged from vb.net 2010.  The error generated from the debugger is:
Problem signature:
  Problem Event Name:      APPCRASH
  Application Name:      Post Office.vshost.exe
  Application Version:      10.0.30319.1
  Application Timestamp:      4ba2084b
  Fault Module Name:      mswsock.dll
  Fault Module Version:      6.1.7601.17514
  Fault Module Timestamp:      4ce7b8e8
  Exception Code:      c0000005
  Exception Offset:      00001823
  OS Version:      6.1.7601.2.1.0.256.4
  Locale ID:      1033
  Additional Information 1:      2f39
  Additional Information 2:      2f39dd6ae8f723c528936f03d74838bc
  Additional Information 3:      6d20
  Additional Information 4:      6d20b7bab49ee09215ee37ad8bde39fe

If you dont close the software and go and reload the table used for emails, then send them it send them all.  It will still hold the orginal one from the first run.
Sub sendEmail(ByVal name As String, _
ByVal campusbox As String, _
ByVal recieveddate As String, _
ByVal shippingmethod As String, _
ByVal trackingnumber As String, _
ByVal packagetype As String, _
ByVal noticelevel As String, _
ByVal locker As String, _
ByVal email As String, _
ByVal originator As String)
        Try
            ''get the settings from the admin table
            If email.Contains("@") Then
                ''create the body of the email
                Dim emailbody As String = ""
                emailbody = emailbody & _
                "Hello " & name & _
                ",<br>" & originator & " shipped a package to your campus box (" & campusbox _
                & ") via " & shippingmethod & " that arrived at the postoffice " & recieveddate _
                & ".<br> The tracking number is " & trackingnumber
                If locker.Length > 0 Then
                    emailbody = emailbody & ".<br> There is a key in your mailbox for the locker that has your package"
                    emailbody = emailbody & ".<br> The locker number is " & locker
                End If
                If packagetype.ToString.Contains("Signature Waived") Then
                    emailbody = emailbody & ".<br> Signature Waived the package is in your Mailbox"
                Else
                    emailbody = emailbody & ".<br> Please bring your valid Gettysburg College ID.<br>"
                End If
                If noticelevel.Length > 0 Then
                    emailbody = emailbody & ".<br> This is the " & noticelevel
                End If
                ''send the email
                Dim oMessage As New Net.Mail.MailMessage()
                oMessage.Subject = emailsubject
                oMessage.Body = emailbody
                oMessage.IsBodyHtml = True
                oMessage.From = New Net.Mail.MailAddress(emailfrom)
                oMessage.To.Add(New Net.Mail.MailAddress(email))
                Dim client As New Net.Mail.SmtpClient(emailsmtpclient)
                If emailnetworkauthentication Then
                    client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
                Else
                    Dim basicAuthenticationInfo As New System.Net.NetworkCredential(emailusername, emailpassword, emaildomain)
                    client.Credentials = basicAuthenticationInfo
                End If
                client.Send(oMessage)
                oMessage.Dispose()
            End If
        Catch ex As Exception
            errorwrite("Email sent to:" & email & " Error String:" & ex.ToString & " Email Macro ")
        End Try

Open in new window

0
Comment
Question by:Millkind
1 Comment
 
LVL 18

Accepted Solution

by:
dj_alik earned 2000 total points
ID: 36895705
By setting System.Net.ServicePointManager.MaxServicePointIdleTime = 1, the mail will send immediately.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Simple Linear Regression
Introduction to Processes

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question