Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Issue when creat send email.... [modified]

Issue when creat send email.... [modified]

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdatabasesysadminsales
9 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Golden Jing
    wrote on last edited by
    #1

    Dear All, I greated small application in VisualStudio2005 to send email with attach file to all my company's customer which take their email from database. So the sending mail process is in loop. I tested lot time . i change their mail to my mail and friends for test. When i click button "Send Mail" it process is complete but i and friend didn't get any mail. Note: our company has to usedd mail server as well. I created a Function like bellow: and Function bellow i imports name space or reference ready. What is issue of this prople? Please give me idea or solution. thanks Under is my function which created.

    Function SendEmail(ByVal mBody As String, ByVal mSubject As String, ByVal mFrom As String, ByVal mTo As String, Optional ByVal mCC As String = "", Optional ByVal mBCC As String = "", Optional ByVal pDisplayName As String = "", Optional ByVal pIsBodyHtml As Boolean = False, Optional ByVal pPriority As MailPriority = MailPriority.Normal, Optional ByVal AttPath As String = "") As Integer
    Dim Mail As New System.Net.Mail.MailMessage
    Dim counter As Integer = 0
    Dim MailAddList() As String
    Dim MailList As String

        Dim Smtp As New SmtpClient
        Try
            With Mail
                .From = New System.Net.Mail.MailAddress(mFrom.Trim, pDisplayName)
                '---- Insert Recepient mail(To) ----
                MailAddList = Split(mTo, ";")
                For Each MailList In MailAddList
                    .To.Add(MailList)
                Next
                .Priority = pPriority
                .IsBodyHtml = pIsBodyHtml
                '---- Insert CC ----
                If mCC <> "" Then
                    MailAddList = Split(mCC, ";")
                    For Each MailList In MailAddList
                        '.To.Add(MailList)
                        .CC.Add(MailList)
                    Next
                End If
                '---- Insert Bcc ----
                If mBCC <> "" Then
                    '.Bcc.Add(mBCC.Trim)
                    MailAddList = Split(mBCC, ";")
                    For Each MailList In MailAddList
                        .Bcc.Add(MailList)
                    Next
                End If
                .Subject = CStr(mSubject).Trim
                .Body = mBody.Trim
                .DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
                'Atach File
                AttFileName = New Attachment(AttPath)
                Mai
    
    D 2 Replies Last reply
    0
    • G Golden Jing

      Dear All, I greated small application in VisualStudio2005 to send email with attach file to all my company's customer which take their email from database. So the sending mail process is in loop. I tested lot time . i change their mail to my mail and friends for test. When i click button "Send Mail" it process is complete but i and friend didn't get any mail. Note: our company has to usedd mail server as well. I created a Function like bellow: and Function bellow i imports name space or reference ready. What is issue of this prople? Please give me idea or solution. thanks Under is my function which created.

      Function SendEmail(ByVal mBody As String, ByVal mSubject As String, ByVal mFrom As String, ByVal mTo As String, Optional ByVal mCC As String = "", Optional ByVal mBCC As String = "", Optional ByVal pDisplayName As String = "", Optional ByVal pIsBodyHtml As Boolean = False, Optional ByVal pPriority As MailPriority = MailPriority.Normal, Optional ByVal AttPath As String = "") As Integer
      Dim Mail As New System.Net.Mail.MailMessage
      Dim counter As Integer = 0
      Dim MailAddList() As String
      Dim MailList As String

          Dim Smtp As New SmtpClient
          Try
              With Mail
                  .From = New System.Net.Mail.MailAddress(mFrom.Trim, pDisplayName)
                  '---- Insert Recepient mail(To) ----
                  MailAddList = Split(mTo, ";")
                  For Each MailList In MailAddList
                      .To.Add(MailList)
                  Next
                  .Priority = pPriority
                  .IsBodyHtml = pIsBodyHtml
                  '---- Insert CC ----
                  If mCC <> "" Then
                      MailAddList = Split(mCC, ";")
                      For Each MailList In MailAddList
                          '.To.Add(MailList)
                          .CC.Add(MailList)
                      Next
                  End If
                  '---- Insert Bcc ----
                  If mBCC <> "" Then
                      '.Bcc.Add(mBCC.Trim)
                      MailAddList = Split(mBCC, ";")
                      For Each MailList In MailAddList
                          .Bcc.Add(MailList)
                      Next
                  End If
                  .Subject = CStr(mSubject).Trim
                  .Body = mBody.Trim
                  .DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
                  'Atach File
                  AttFileName = New Attachment(AttPath)
                  Mai
      
      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      Can you reformat your original post and stick the code in a pre block? that would make it easier to read for a starter. also sort out your blocks.

      Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

      G 1 Reply Last reply
      0
      • G Golden Jing

        Dear All, I greated small application in VisualStudio2005 to send email with attach file to all my company's customer which take their email from database. So the sending mail process is in loop. I tested lot time . i change their mail to my mail and friends for test. When i click button "Send Mail" it process is complete but i and friend didn't get any mail. Note: our company has to usedd mail server as well. I created a Function like bellow: and Function bellow i imports name space or reference ready. What is issue of this prople? Please give me idea or solution. thanks Under is my function which created.

        Function SendEmail(ByVal mBody As String, ByVal mSubject As String, ByVal mFrom As String, ByVal mTo As String, Optional ByVal mCC As String = "", Optional ByVal mBCC As String = "", Optional ByVal pDisplayName As String = "", Optional ByVal pIsBodyHtml As Boolean = False, Optional ByVal pPriority As MailPriority = MailPriority.Normal, Optional ByVal AttPath As String = "") As Integer
        Dim Mail As New System.Net.Mail.MailMessage
        Dim counter As Integer = 0
        Dim MailAddList() As String
        Dim MailList As String

            Dim Smtp As New SmtpClient
            Try
                With Mail
                    .From = New System.Net.Mail.MailAddress(mFrom.Trim, pDisplayName)
                    '---- Insert Recepient mail(To) ----
                    MailAddList = Split(mTo, ";")
                    For Each MailList In MailAddList
                        .To.Add(MailList)
                    Next
                    .Priority = pPriority
                    .IsBodyHtml = pIsBodyHtml
                    '---- Insert CC ----
                    If mCC <> "" Then
                        MailAddList = Split(mCC, ";")
                        For Each MailList In MailAddList
                            '.To.Add(MailList)
                            .CC.Add(MailList)
                        Next
                    End If
                    '---- Insert Bcc ----
                    If mBCC <> "" Then
                        '.Bcc.Add(mBCC.Trim)
                        MailAddList = Split(mBCC, ";")
                        For Each MailList In MailAddList
                            .Bcc.Add(MailList)
                        Next
                    End If
                    .Subject = CStr(mSubject).Trim
                    .Body = mBody.Trim
                    .DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
                    'Atach File
                    AttFileName = New Attachment(AttPath)
                    Mai
        
        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        I would suggest you first try and break down the issue into smaller chunks and build it up progressively. 1) Start by searching this forum, this has been discussed before many times and there are definitely code samples available (i know because i posted one for sending email via gmail, the process is the same, just different ip's + ports) 2) Is your SMTP port correct? doesn't look like a standard SMTP port (usually 25) 3) Does your SMTP require authentication? 4) Try sending a basic text message first, single hardcoded email address, with no attachments does that work? Build on it from there.

        Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

        G 1 Reply Last reply
        0
        • D DaveAuld

          I would suggest you first try and break down the issue into smaller chunks and build it up progressively. 1) Start by searching this forum, this has been discussed before many times and there are definitely code samples available (i know because i posted one for sending email via gmail, the process is the same, just different ip's + ports) 2) Is your SMTP port correct? doesn't look like a standard SMTP port (usually 25) 3) Does your SMTP require authentication? 4) Try sending a basic text message first, single hardcoded email address, with no attachments does that work? Build on it from there.

          Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

          G Offline
          G Offline
          Golden Jing
          wrote on last edited by
          #4

          I test manually that send to 2 email (yahoo, and gmail) and cc 1 email (our company mail) with attach file. When i check i got in gmail. around 5 or 6 hour i got in our company mail. But about yahoo i don't get it at all. I don't know that is issue. If have any solving please let me know. gold_sovann@yahoo.com Thanks

          VB.Net

          D 1 Reply Last reply
          0
          • G Golden Jing

            I test manually that send to 2 email (yahoo, and gmail) and cc 1 email (our company mail) with attach file. When i check i got in gmail. around 5 or 6 hour i got in our company mail. But about yahoo i don't get it at all. I don't know that is issue. If have any solving please let me know. gold_sovann@yahoo.com Thanks

            VB.Net

            D Offline
            D Offline
            DaveAuld
            wrote on last edited by
            #5

            Maybe you have some spam filters as part of the yahoo mail turned on. This is just canning the message. Did you try sending a basic message without any attachments etc. to yahoo, did this work? The fact you received the message on gmail and company mail would suggest it is working and it is the mail providers causing the loss of message.

            Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

            G 1 Reply Last reply
            0
            • D DaveAuld

              Maybe you have some spam filters as part of the yahoo mail turned on. This is just canning the message. Did you try sending a basic message without any attachments etc. to yahoo, did this work? The fact you received the message on gmail and company mail would suggest it is working and it is the mail providers causing the loss of message.

              Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

              G Offline
              G Offline
              Golden Jing
              wrote on last edited by
              #6

              By the way i tested to send it. i got testing mail it was in Spam folder not into Inbox. why is like that? and when i test send to 7 or 8 customer with loop i did not get mail. What problem ?

              VB.Net

              D 1 Reply Last reply
              0
              • G Golden Jing

                By the way i tested to send it. i got testing mail it was in Spam folder not into Inbox. why is like that? and when i test send to 7 or 8 customer with loop i did not get mail. What problem ?

                VB.Net

                D Offline
                D Offline
                DaveAuld
                wrote on last edited by
                #7

                The problem is your message must look like its is being dumped by all the mail servers because it looks like SPAM. Pure and simple. You have already said it is sending the messages and they are being received by some account, and not others. And even one appeared in the spam folder. Change the layout of your message, add more text into the body, have a decent subject, give the attachments meaningful names etc. etc. all these things will reduce the likelihood of it being interrupted as spam.

                Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                G 1 Reply Last reply
                0
                • D DaveAuld

                  The problem is your message must look like its is being dumped by all the mail servers because it looks like SPAM. Pure and simple. You have already said it is sending the messages and they are being received by some account, and not others. And even one appeared in the spam folder. Change the layout of your message, add more text into the body, have a decent subject, give the attachments meaningful names etc. etc. all these things will reduce the likelihood of it being interrupted as spam.

                  Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                  G Offline
                  G Offline
                  Golden Jing
                  wrote on last edited by
                  #8

                  Thanks you Dave. I will try to test it again. If you have any new of that issue please let me know. Best regards

                  VB.Net

                  1 Reply Last reply
                  0
                  • D DaveAuld

                    Can you reformat your original post and stick the code in a pre block? that would make it easier to read for a starter. also sort out your blocks.

                    Dave GoogleWave: dave.m.auld[at]googlewave.com Who am I?: Web|Facebook|Twitter|LinkedIn|Bebo

                    G Offline
                    G Offline
                    Golden Jing
                    wrote on last edited by
                    #9

                    Function SendEmail(ByVal mBody As String, ByVal mSubject As String, ByVal mFrom As String, ByVal mTo As String, Optional ByVal mCC As String = "", Optional ByVal mBCC As String = "", Optional ByVal pDisplayName As String = "", Optional ByVal pIsBodyHtml As Boolean = False, Optional ByVal pPriority As MailPriority = MailPriority.Normal, Optional ByVal AttPath As String = "") As Integer
                    Dim Mail As New System.Net.Mail.MailMessage
                    Dim counter As Integer = 0
                    Dim MailAddList() As String
                    Dim MailList As String

                        Dim Smtp As New SmtpClient
                        Try
                            With Mail
                                .From = New System.Net.Mail.MailAddress(mFrom.Trim, pDisplayName)
                                '---- Insert Recepient mail(To) ----
                                MailAddList = Split(mTo, ";")
                                For Each MailList In MailAddList
                                    .To.Add(MailList)
                                Next
                                .Priority = pPriority
                                .IsBodyHtml = pIsBodyHtml
                                '---- Insert CC ----
                                If mCC <> "" Then
                                    MailAddList = Split(mCC, ";")
                                    For Each MailList In MailAddList
                                        '.To.Add(MailList)
                                        .CC.Add(MailList)
                                    Next
                                End If
                                '---- Insert Bcc ----
                                If mBCC <> "" Then
                                    '.Bcc.Add(mBCC.Trim)
                                    MailAddList = Split(mBCC, ";")
                                    For Each MailList In MailAddList
                                        .Bcc.Add(MailList)
                                    Next
                                End If
                                .Subject = CStr(mSubject).Trim
                                .Body = mBody.Trim
                                .DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
                                'Atach File
                                AttFileName = New Attachment(AttPath)
                                Mail.Attachments.Add(AttFileName)
                    
                            End With
                            Smtp.Host = CStr("company.test.com.kh") 'It's replace the IP
                            Smtp.Port = 25
                            Dim myCredential As New System.Net.NetworkCredential("UserName", "Password")
                            Smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
                            Smtp.Credentials = myCredential
                    
                            Smtp.Send(Mail)
                            '----- Delay process 10seconds ------'
                            System.Threading.Thread.Sleep(10000)
                            '-----------------------------------'
                            Return 0
                        Catch ex As Exception
                            ErrorMessage = ex
                    
                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups