Solved

Email only sends after the program is closed.

Posted on 2011-09-30
1
231 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 500 total points
ID: 36895705
By setting System.Net.ServicePointManager.MaxServicePointIdleTime = 1, the mail will send immediately.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now