-
Oct 22nd, 2014, 07:32 PM
#41
Fanatic Member
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
-
May 31st, 2016, 01:04 PM
#42
New Member
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?
-
Jan 28th, 2017, 07:34 AM
#43
Addicted Member
Re: vb6 - send email with attachment using smtp
-
Sep 9th, 2017, 11:10 PM
#44
Re: vb6 - send email with attachment using smtp
Originally Posted by Kars Lensen
You should be getting (much) more praise for sharing this tip
Thanks,
rob
-
Nov 4th, 2017, 04:22 PM
#45
New Member
Re: vb6 - send email with attachment using smtp
Hello
Any one know how to attach more than one file ?
Thanks
-
Nov 4th, 2017, 10:49 PM
#46
Re: vb6 - send email with attachment using smtp
Originally Posted by Motero69
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"
-
Feb 28th, 2019, 05:26 AM
#47
New Member
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
-
Feb 28th, 2019, 05:27 AM
#48
New Member
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
-
Feb 28th, 2019, 05:41 AM
#49
New Member
Re: vb6 - send email with attachment using smtp
Sorry!
I have overlooked the post before.
Only the topic "Progressbar" remains
-
Mar 2nd, 2021, 03:36 AM
#50
New Member
Re: vb6 - send email with attachment using smtp
For Gmail account set this:
Allow less secure apps: ON
-
Mar 2nd, 2021, 03:47 AM
#51
New Member
Re: vb6 - send email with attachment using smtp
Originally Posted by damasterjo
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|