Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending an email through VB6

Tags:

email

vb6

I am wondering if there is a way to send an email (SMTP) through VB6. I have an application that just needs to send a simple email when the user is done to let a group know that the application has processed. Is there a way to do that?

like image 881
gary A.K.A. G4 Avatar asked Apr 01 '11 18:04

gary A.K.A. G4


People also ask

What is EASendMail EXE?

EASendMail namespace contains pure . NET classes that allow you to construct and send email messages in VB.NET, C#, ASP.NET or any managed applications. Email message can be delivered through either arbitrary SMTP email service or dns lookup without specified SMTP server.

What is report vb6?

Visual Basic (VB) 6 introduced the new Data Report Designer as a way to create reports from within VB. This reporting tool increases developers' control over report execution.


2 Answers

Yep - depends on which version of windows you're using. Assuming one of the later versions - CDO.Message works great.

Sub SendMessage(MailFrom,MailTo,Subject,Message)
    Dim ObjSendMail
    Set ObjSendMail = CreateObject("CDO.Message")

    'This section provides the configuration information for the remote SMTP server.

    With ObjSendMail.Configuration.Fields
    .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smpt server Address"
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

    ' If your server requires outgoing authentication uncomment the lines below and use a valid email address and password.
'    .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
'    .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = MailFrom
'    .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = yourpassword

    .Update
    End With

    'End remote SMTP server configuration section==

    ObjSendMail.To = MailTo
    ObjSendMail.Subject = Subject
    ObjSendMail.From = MailFrom

    ' we are sending a html email.. simply switch the comments around to send a text email instead
    ObjSendMail.HTMLBody = Message
    'ObjSendMail.TextBody = Message

    ObjSendMail.Send

    Set ObjSendMail = Nothing
End Sub
like image 148
Dave Avatar answered Oct 05 '22 17:10

Dave


I found this here:

Dim UserName$, UserMail$, MailRecipiant$, MailBody$, SockData$

Private Sub Command1_Click()
UserName = "YourUserName_or_Addr"
UserMail = "Your Name <[email protected]>"
MailRecipiant = UserMail
MailBody = "The message goes here"
Winsock1.LocalPort = 0
Winsock1.RemoteHost = "smtp-server"
Winsock1.RemotePort = 25
Winsock1.Connect
End Sub

Private Sub Winsock1_Connect()
Label1 = "Sending message..."
Winsock1.SendData "EHLO " & UserName & vbCrLf
If Not WaitFor("250") Then GoTo 100
Winsock1.SendData "MAIL FROM: " & UserMail & vbCrLf
If Not WaitFor("250") Then GoTo 100
Winsock1.SendData "RCPT TO: " & MailRecipiant & vbCrLf
If Not WaitFor("250") Then GoTo 100
Winsock1.SendData "DATA" & vbCrLf
If Not WaitFor("354") Then GoTo 100
Winsock1.SendData MailBody & vbCrLf & "." & vbCrLf
If Not WaitFor("250") Then GoTo 100
Winsock1.SendData "QUIT" & vbCrLf
If Not WaitFor("221") Then GoTo 100
Label1 = "Message sent"
GoTo 200
100
Label1 = SockData
200
Winsock1.Close
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData SockData
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Label1 = "Error: " & Description
SockData = "Error"
Winsock1.Close
End Sub

Private Function WaitFor(SockResponse As String) As Boolean
Do While Left(SockData, 3) <> SockResponse And Left(SockData, 3) <> "220" And Left(SockData, 3) <> "250"
  DoEvents
  If Left(SockData, 3) > "400" Then Exit Function
Loop
WaitFor = 1
SockData = ""
End Function
like image 28
SQLMason Avatar answered Oct 05 '22 18:10

SQLMason