Sending Email not received?

rjgagui

Member
Joined
Nov 5, 2014
Messages
18
Programming Experience
Beginner
Hello guys, im sending email with a PDF attachment.
VB.NET:
        Dim mail As New MailMessage()
        Dim smtp As New SmtpClient()
        Dim attach As Attachment




        Try


            If rbPdf.Checked = True Then
                attach = New Attachment(pdfFile)
            Else
                attach = New Attachment(sourcepath)
            End If


            Dim mailto As String = "email@gmail.com"
           
            mail.To.Add(mailto)
            mail.From = New MailAddress("emailSender@some.com")
          
            mail.Attachments.Add(New Attachment(pdfFile))
            mail.IsBodyHtml = True
            mail.Subject = "Transmittal Report"


            mail.Body = Replace(txtEmailBody.Text, "imageName", If(UserID = 60 Or UserID = 61, "shiela", "marie"))
          
            smtp.Host = "mail.some.com"


            smtp.UseDefaultCredentials = False
            smtp.Port = 26


            'smtp.Port = 25
         
            smtp.Credentials = New NetworkCredential("emailSender@some.com", "12345")
         


        
            smtp.EnableSsl = False
            smtp.Send(mail)


            MsgBox("Email Sent.", vbInformation, "Transmittal Report")
            attach.Dispose()
            mail.Dispose()
            smtp.Dispose()

im using this code in sending excel files, my problem is when i use this code in sending PDF, it does not send consistently. example : i send email 1, it will be then received by the receipient, then send email 2, for some reason the email is not received but with no error on vb part or bounce message on email.. i dont know where is the problem.. please help me guys... (sorry for my bad english).
 
So are you saying that every time you execute that code twice, the first message is received and the second isn't? If not then please speak plainly. If it's random, or at least appears to be, then please say that.
 
So are you saying that every time you execute that code twice, the first message is received and the second isn't? If not then please speak plainly. If it's random, or at least appears to be, then please say that.

sorry about the confusion.. actually its random. but not so random since i have experience a consequtive sending failure (email not received.), oh i forgot, i only experience this if sending to gmail, but not on yahoo or other email..
 
Last edited:
There is an inconsistency in code here:
If rbPdf.Checked = True Then
attach = New Attachment(pdfFile)
Else
attach = New Attachment(sourcepath)
End If
'attach' is not used further in code.
mail.Attachments.Add(New Attachment(pdfFile))
We can see that you start a Try block, but not how you handle possible exceptions.
 
There is an inconsistency in code here:

'attach' is not used further in code.

We can see that you start a Try block, but not how you handle possible exceptions.

sorry about that..

mail.Attachments.Add(New Attachment(pdfFile)) should be mail.Attachments.Add(attach).. but since i only test the pdf that's y i change it temporarily to pdfFile directly.
 
Back
Top