Click here to Skip to main content
15,889,843 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
When I send mail from my vb6 application an error occure as ``530 5.7.0 Must issue a STARTTLS command first. 2sm15398699pbx.70``

I try to send mail via Outlook.

SMTPHOST : smtp.gmail.com
SMTPPORT : 587

Sender ID : my@gmail.com

How can I solve this problem in vb6.
Posted

1 solution

Hi
Use this code:

VB
'http://www.programming.rzb.ir | visit me ;D
Option Explicit

'start SendMail code
Function SendMail(Sender As String, Subject As String, Reciever As String, Text As String, Password As String, AttachFile As String, mailserver As String, portnum As String) As Boolean
    If Sender <> "" Or Password <> "" Then
        Dim iMsg, iConf, Flds, schema, SendEmailGmail
        Set iMsg = CreateObject("CDO.Message")
        Set iConf = CreateObject("CDO.Configuration")
        Set Flds = iConf.Fields
    
        ' send one copy with Google SMTP server (with autentication)
        schema = "http://schemas.microsoft.com/cdo/configuration/"
        Flds.Item(schema & "sendusing") = 2
        Flds.Item(schema & "smtpserver") = mailserver
        Flds.Item(schema & "smtpserverport") = portnum
        Flds.Item(schema & "smtpauthenticate") = 1
        Flds.Item(schema & "sendusername") = Sender
        Flds.Item(schema & "sendpassword") = Password
        Flds.Item(schema & "smtpusessl") = 1
        Flds.Update
    
        With iMsg
            DoEvents
            .To = Reciever
            .From = Sender
            .Subject = Subject
            .HTMLBody = Text
            .Sender = Sender
            .Organization = "S.M.B Productions"
            .ReplyTo = Sender
            If AttachFile <> "" Then
                .AddAttachment (AttachFile)
            End If
            Set .Configuration = iConf
            SendEmailGmail = .send
        End With
    
        Set iMsg = Nothing
        Set iConf = Nothing
        Set Flds = Nothing
        SendMail = True
    Else
        MsgBox "Please, Fill the Sender Mail Address or Sender Mail Password", vbCritical, "Connection Error"
        SendMail = False
    End If
End Function
 
Share this answer
 
v2
Comments
Member 13922896 23-Jul-18 10:04am    
This runs too slowly any recommendetion?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900