Page 2 of 2 FirstFirst 12
Results 41 to 51 of 51

Thread: vb6 - send email with attachment using smtp

  1. #41
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: vb6 - send email with attachment using smtp

    i just set up a new gmail and its fine... go figure...
    Software languages known:
    Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
    Software API's known:
    Directx 7 and 8
    Internet languages, in the process of learning:
    HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX

  2. #42
    New Member
    Join Date
    Feb 2015
    Posts
    9

    Re: vb6 - send email with attachment using smtp

    I had a working email client a few years back. Then it started throwing errors. I followed recommendations on this this thread, and changed everything that was recommended. It didn't correct the errors. I have checked with Hotmail(outlook now), g-mail and yahoo, and the reason is that this function alone does not comply with security measure now implemented in their web mail clients.

    Has anyone got it to work against these new security parameters?

  3. #43
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Re: vb6 - send email with attachment using smtp


  4. #44
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: vb6 - send email with attachment using smtp

    Quote Originally Posted by Kars Lensen View Post
    You should be getting (much) more praise for sharing this tip
    Thanks,
    rob

  5. #45
    New Member
    Join Date
    Nov 2017
    Posts
    1

    Re: vb6 - send email with attachment using smtp

    Hello

    Any one know how to attach more than one file ?

    Thanks

  6. #46
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: vb6 - send email with attachment using smtp

    Quote Originally Posted by Motero69 View Post
    Hello
    Any one know how to attach more than one file ?
    Thanks
    Yes
    I have had this project on my PC for a while, and had changed the data to use my own email provider (iPrimus in australia)
    But that should not effect the code.
    I have enhanced the code to handle multiple attachments, by allowing you to add more file names, separated with comma's
    Here is the modified code -
    Code:
    Option Explicit
    
    
    Public Function SendMail(sTo As String, sSubject As String, sFrom As String, _
        sBody As String, sSmtpServer As String, iSmtpPort As Integer, _
        sSmtpUser As String, sSmtpPword As String, _
        sFilePathAndFiles As String, bSmtpSSL As Boolean) As String
          
        On Error GoTo SendMail_Error:
        '20171105
        Dim sArr() As String, sFilePathONLY As String, sFiles As String, i As Integer, sFileNameWithPath As String
        Dim lobj_cdomsg      As CDO.Message
        Set lobj_cdomsg = New CDO.Message
        lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = sSmtpServer
        lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = iSmtpPort
        lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
        lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = cdoBasic
        lobj_cdomsg.Configuration.Fields(cdoSendUserName) = sSmtpUser
        lobj_cdomsg.Configuration.Fields(cdoSendPassword) = sSmtpPword
        lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 60      'WAs 30  I changed to 60 20170910 15:47
        lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = cdoSendUsingPort
        lobj_cdomsg.Configuration.Fields.Update
        lobj_cdomsg.To = sTo
        lobj_cdomsg.From = sFrom
        lobj_cdomsg.Subject = sSubject
        lobj_cdomsg.TextBody = sBody
        'If Trim$(sFilePath) <> vbNullString Then
        '    lobj_cdomsg.AddAttachment (sFilePath)
        'End If
        '20171105 Enhanced to cater for multiple attachments
        If Trim$(sFilePathAndFiles) <> vbNullString Then
            If InStr(1, sFilePathAndFiles, ",") Then
                'Multiple attachements are present, so split the filenames (assumption that they are all in the same folder)
                sArr = Split(sFilePathAndFiles, "\")
                sFiles = sArr(UBound(sArr))
                'Remove the File names from sFilePathAndFiles
                sFilePathONLY = Replace(sFilePathAndFiles, sFiles, "")
                sArr = Split(sFiles, ",")
                For i = 0 To UBound(sArr)
                    sFileNameWithPath = (sFilePathONLY & sArr(i))
                    lobj_cdomsg.AddAttachment sFileNameWithPath
                Next i
            Else
                'There is only one file to attach
                sFileNameWithPath = (sFilePathAndFiles)
                lobj_cdomsg.AddAttachment (sFilePathAndFiles)
            End If
        End If
        
        
        lobj_cdomsg.Send
        Set lobj_cdomsg = Nothing
        SendMail = "ok"
        Exit Function
              
    SendMail_Error:
        Debug.Print sFileNameWithPath
        Debug.Print Err.Description
        SendMail = Err.Description
    End Function
    
    
    Private Sub cmdSend_Click()
        
        Dim retVal          As String
        Dim objControl      As Control
        'Validate first
        For Each objControl In Me.Controls
            If TypeOf objControl Is TextBox Then
                If Trim$(objControl.Text) = vbNullString And LCase$(objControl.Name) <> "txtattach" Then
                    lblStatus.Caption = "Error: All fields are required!"
                    Exit Sub
                End If
            End If
        Next
        
        'Send
        Frame1.Enabled = False
        Frame2.Enabled = False
        cmdSend.Enabled = False
        lblStatus.Caption = "Sending..."
        retVal = SendMail(Trim$(txtTo.Text), _
            Trim$(txtSubject.Text), _
            Trim$(txtFromName.Text) & "<" & Trim$(txtFromEmail.Text) & ">", _
            Trim$(txtMsg.Text), _
            Trim$(txtServer.Text), _
            CInt(Trim$(txtPort.Text)), _
            Trim$(txtUsername.Text), _
            Trim$(txtPassword.Text), _
            Trim$(txtAttach.Text), _
            CBool(chkSSL.Value))
        Frame1.Enabled = True
        Frame2.Enabled = True
        cmdSend.Enabled = True
        lblStatus.Caption = IIf(retVal = "ok", "Message sent!", retVal)
        
    End Sub
    
    Private Sub Form_Load()
        'txtAttach.Text = App.Path & "\" & "Test_CDO_email.txt"
        txtAttach.Text = App.Path & "\" & "Test_CDO_email.txt,Test_CDO_email_File_2.txt,Test_CDO_email_File_3.txt"
    End Sub
    
    'ROBs   Place error message into clipboard, by clicking the Status Label
    Private Sub lblStatus_Click()
        Clipboard.Clear
        Clipboard.SetText lblStatus.Caption
    End Sub
    Rob
    PS I am on many occasions getting this error, but it does not happen all the time, so I assume it is my email host telling me to bug off -
    "The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available"

  7. #47
    New Member
    Join Date
    Feb 2019
    Posts
    3

    Re: vb6 - send email with attachment using smtp

    Hi,

    I have tried send email with attachment and it works very well.
    How can I insert several attachments?
    Could you still integrate a progressbar?

    greetings

  8. #48
    New Member
    Join Date
    Feb 2019
    Posts
    3

    Re: vb6 - send email with attachment using smtp

    Hi,

    I have tried send email with attachment and it works very well.
    How can I insert several attachments?
    Could you still integrate a progressbar?

    greetings

  9. #49
    New Member
    Join Date
    Feb 2019
    Posts
    3

    Re: vb6 - send email with attachment using smtp

    Sorry!
    I have overlooked the post before.
    Only the topic "Progressbar" remains

  10. #50
    New Member
    Join Date
    Jan 2016
    Posts
    4

    Re: vb6 - send email with attachment using smtp

    For Gmail account set this:
    Allow less secure apps: ON

  11. #51
    New Member
    Join Date
    Jan 2016
    Posts
    4

    Re: vb6 - send email with attachment using smtp

    Quote Originally Posted by damasterjo View Post
    Ok I have used this code and have the same error.
    using gmail, smpt.gmail.com port 465

    i have used 3 machines for test, windows 7 64bit windows 8.1 64 bit, windows xp.
    same error. password is correct

    any ideas?
    For Gmail set:
    Allow less secure apps: ON

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width