Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15536

Send Email

$
0
0
I've tried several online sites as to how to send emails. Sadly I can never get any to work. Does anyone have the code that actually works in VB6. Here is what I have now. Is anything wrong? Thanks in advance!

Sub SendEmail()
On Error Resume Next 'Set up error checking

Set cdoMsg = CreateObject("CDO.Message")
Set cdoConf = CreateObject("CDO.Configuration")
Set cdoFields = cdoConf.Fields
'Send one copy with Google SMTP server
schema = "http://schemas.microsoft.com/cdo/configuration/"
cdoFields.Item(schema & "sendusing") = 2
cdoFields.Item(schema & "smtpserver") = smtp.gmail.com
cdoFields.Item(schema & "smtpserverport") = 465
cdoFields.Item(schema & "smtpauthenticate") = 1
cdoFields.Item(schema & "sendusername") = "myemail@gmail.com" ' Not my actual Email
cdoFields.Item(schema & "sendpassword") = "Password" 'Not actual Password
cdoFields.Item(schema & "smptusess1") = 1
cdoFields.Update
With cdoMsg
.To = "theiremail@gmail.com"
.From = "myemail@gmail.com"
.Subject = "Electricity Usage"
'Body of message can be any HTML code
.HTML = " Test message using cdo in VB6 to Gmail smtp"
'Add any attachments to the message
'.AddAttachment "C:\accdo.ico"
Set .Configuration = cdoConf
'Send the message
.Send
End With
'Check for errors and display message
If Err.Number = 0 Then
MsgBox "Email Send Successfully", , "Email"
Else
MsgBox "Email Error" & Err.Number, , "Email"
End If
Set cdoMsg = Nothing
Set cdoConf = Nothing
Set cdoFields = Nothing
End Sub
Private Sub Command5_Click()
Call SendEmail
End Sub

Viewing all articles
Browse latest Browse all 15536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>