Sending Email Via VB6

I am wondering if there is a way to send an email (SMTP) via VB6. I have an application that just needs to send a simple email when the user is ready so that the group finds out that the application has been processed. Is there any way to do this?

+6
email vb6 email-integration
source share
5 answers

Yep - depends on which version of windows you are using. Assuming one of the later versions - CDO.Message works fine.

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 
+10
source share

We hope that CDOSYS libraries will be installed on your computer:

CDO Messaging - MSDN
Compose and send a message - MSDN
Sending Email Using CDOSYS (REAL MESSAGE)
ASP Sending Email Using CDOSYS

If you do not have this library (and you cannot install it), then CDONTS is always returned, but it is deprecated:

Using the CDONTS component to send email from ASP pages.

+3
source share

I found here here :

 Dim UserName$, UserMail$, MailRecipiant$, MailBody$, SockData$ Private Sub Command1_Click() UserName = "YourUserName_or_Addr" UserMail = "Your Name < You@provider.com >" 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 
+3
source share

Dave has a good solution if you really need to send email from a client PC. However, sometimes there are problems with firewalls, etc. In the case when you connect to SQL Server, I found that to simplify and simplify the management if you proxy your mail through SQL Server (either by queuing it in the outgoing mail table or by calling the xp_sendmail stored process).

Here is a tutorial on how to configure SQL Mail and work on the server, and at the end shows how to use the stored procedure for sending email.

I found this solution useful because:

  • Windows 7 computers blocked all outgoing SMTP
  • The implementation of all attempts, etc. for outgoing email, the β€œcorrect” one was rather complicated.
  • Using the queue method with SQL Server, but without actually creating SQL Mail in my development database or tests, emails remained in the queue if I did not work with the production server
0
source share

We used OstroSoft SMTP control with very good results.

0
source share

All Articles