SMTP, fumbles handoff?

ccbryan

Active member
Joined
Oct 14, 2008
Messages
30
Programming Experience
5-10
Hello all. I am in the process of implementing a VB.NET application (VS2005, Framework 2.0) that generates an email upon invoicing and attaches PDF copies of the invoice and shipping documents. The emailing portion of the app, using SMTP, has worked without problem for weeks. Yesterday morning I ran a successful test in the live environment, and then after that I was unable to generate another email with my app. Nothing in my code or my config file changed between success instance and failure instance. No error is produced or displayed... just no email.

I spent all day yesterday juggling my code, restoring backup copies, creating test modules -- but all in vain. I could not produce an email.

This morning I returned to the project, determined to step through it once more... and it worked. First time and each time thereafter.

I am certain that my VB code was not responsible for the cessation or the resumption of email generation. Yesterday I verified that the SMTP service was running on the email server... I stopped and restarted it but to no avail. I pulled up the inetpub\mailroot folders and watched them as I executed my code, but no files appeared there.

My application is on Server1; the Email server is Server2. Both servers are within an internal domain.

The question: what could cause smptmail.send() to work one moment and not the next and then work again the next day? What could get in between VB and SMTP to prevent email generation??

Any help will be received with an almost embarassing amount of gratitude.


FYI , here's my email class. This code works. When it was failing by the way, no exception was generated -- I was watching 'ex' in debug mode.



Code:

VB.NET:
Imports Microsoft.VisualBasic 
Imports System.net.Mail 

Public Class SendEmail 
  public SMTPHost as string 
  public SMTPPort as String 
  public MailLogin as String 
  Public MailPwd as String 
  Public MailCC as string 

Public Sub SendEmailMessage(ByVal strFrom As String, ByVal strTo() _ 
    As String, ByVal strSubject _ 
    As String, ByVal strMessage _ 
    As String, ByVal fileList() As String) 
   
        SMTPHost = System.Configuration.ConfigurationSettings.AppSettings("SMTPHost") 
        SMTPPOrt = System.Configuration.ConfigurationSettings.AppSettings("SMTPPort") 
        MailLogin = System.Configuration.ConfigurationSettings.AppSettings("MailLogin") 
        MailPwd = System.Configuration.ConfigurationSettings.AppSettings("MailPwd") 
        MailCC = System.Configuration.ConfigurationSettings.AppSettings("MailCC") 
        'This procedure takes string array parameters for multiple recipients and files 
        Try 
            For Each item As String In strTo 
                'For each to address create a mail message 
                Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(item)) 
                MailMsg.BodyEncoding = system.Text.Encoding.Default 
                MailMsg.Subject = strSubject.Trim() 
                MailMsg.Body = strMessage.Trim() & vbCrLf 
                MailMsg.Priority = MailPriority.High 
                MailMsg.IsBodyHtml = True 
                MailMsg.CC.Add(MailCC) 

                'attach each file attachment 
                For Each strfile As String In fileList 
                    If Not strfile = "" Then 
                        Dim MsgAttach As New Attachment(strfile) 
                        MailMsg.Attachments.Add(MsgAttach) 
                    End If 
                Next 

                'Smtpclient to send the mail message 
                Dim SmtpMail As New SmtpClient 

                Dim icred As New System.Net.NetworkCredential 
                icred.Password = MailPwd 
                icred.UserName = MailLogin 
                SmtpMail.Credentials = icred 
                'smtpmail.UseDefaultCredentials = true 

                SmtpMail.Host = SMTPHost 
                SmtpMail.Port = SMTPPort 
                SmtpMail.Send(MailMsg) 


            Next 
            'Message Successful 
        Catch ex As Exception 
            'Message Error 
            Messagebox.show(ex)
        End Try 
    End Sub 

End Class
 
1. Is Option Strict on?

2. "SmtpMail.Port" accepts an integer, yet you are passing it a string.

3. I know you are not re-using it, but would MailMsg.Dispose() help?

Just throwing ideas around - they may not help :(
 
Back
Top