-
February 14th, 2009, 03:37 AM
#1
Making a VB6 application send an email?
Hi
I would like to know how to send an email through a VB6 application. I'm using WizBang's Winsock-SMTP Server mailer. So far I've got...
Code:
Dim UserName$, UserMail$, MailRecipiant$, MailBody$, SockData$
Private Sub Command1_Click()
UserName = "JetlagJad"
UserMail = "Jarryd <jarryd-1995@hotmail.com>"
MailRecipiant = UserMail
MailBody = "The message goes here"
Winsock1.LocalPort = 0
Winsock1.RemoteHost = "smtp.gmail.com"
Winsock1.RemotePort = 587
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
I get the error message:
530 5.7.0 Must issue a STARTTLS command first. f42sm2188083rvb.3
Thanks in advance! Oh and by the way.. first post! Woohoo!
-
February 14th, 2009, 05:36 AM
#2
Re: Making a VB6 application send an email?
First of all, the first command should be "HELO" not "EHLO"
secondly the port number for SMTP SERVERS is usually 25, although this may be a secured socket and needs aditional programming, you will have to talk to other ppl about that or try using a different server. I have this same code and it works ok for me.
-
February 14th, 2009, 08:02 AM
#3
Re: Making a VB6 application send an email?
Originally Posted by JetlagJad
Hi
I get the error message:
530 5.7.0 Must issue a STARTTLS command first. f42sm2188083rvb.3
Thanks in advance! Oh and by the way.. first post! Woohoo!
GMail requires an encrypted connection to send email. I personally don't know of VB6 TLS implementation. You will probably need to use a 3rd party control to send mail through google.
Now if you are sending EMail to a gmail account, you can use port 25 and the code just like you have posted and it should work, IF you ISP allows you to connect out on port 25.
ETA: Welcome to the boards
Last edited by sotoasty; February 14th, 2009 at 08:03 AM.
Reason: Add Welcome
-
February 14th, 2009, 08:46 PM
#4
Re: Making a VB6 application send an email?
So what SMTP servers do you suggest I could use??
-
February 14th, 2009, 09:54 PM
#5
Re: Making a VB6 application send an email?
You don't need a third party control. As long as you have an account on gmail you can use their smtp server. Try port 465 as this is a secured server and you will need to do SSL authentication.
Also, I strongly recommend using CDO instead of Winsock. Go to this link for full CDO code in the thread and how to set up with gmail.
http://www.xtremevbtalk.com/showthread.php?t=304277
-
February 14th, 2009, 11:12 PM
#6
Re: Making a VB6 application send an email?
type MAILTO: from the command line. if it opens OUTLOOK/Express, you're under the SP2 ruleset. You can NOT send automated email anymore, guys!!!
-
February 15th, 2009, 11:17 AM
#7
Re: Making a VB6 application send an email?
Originally Posted by dglienna
type MAILTO: from the command line. if it opens OUTLOOK/Express, you're under the SP2 ruleset. You can NOT send automated email anymore, guys!!!
dglienna, I respect you but what are you talking about? MAILTO is basically a shortcut to open up the default mail provider. Here they are talking about sending an e-mail to a mail server. Using the code above does nothing with OE or Outlook. Some ISP's are putting re-directs on port 25 but not all. Mine does. In fact, I had to open a different port on our e-mail server so that I can send email from home, as all connections on port 25 are re-directed to my ISPs mailserver. It is a very effective way of blocking mass mailing programs.
Jet,
As Tom stated, CDO might be the best way to go. Or you might check this link out (courtesy of George1111).
http://www.freevbcode.com/ShowCode.Asp?ID=109
-
February 15th, 2009, 09:29 PM
#8
Re: Making a VB6 application send an email?
Won't work if the pc has SP2 or greater
-
February 16th, 2009, 07:28 AM
#9
Re: Making a VB6 application send an email?
Your PC can't block port 25. Well, that's not true. The firewall can block port 25 going out or you AV software can. But all you have to do is add an exception for your application. Personally, I think this is one of the most vile things that the AV/Windows designers do. I don't need them telling me what to do with my Applications.
However, the above code will work fine on ANY MailServer that does not require TLS. There is/and can be nothing in SP2 to block all applications connecting on port 25. I use similar code in my applications. We have over 100 people using XP sp2 and 3. Some useing Vista SP1. We have a 2nd and 3rd Offices mostly on XP. Everyone of them can and do send e-mail on a daily basis, through my application.
It will work. All you have to do is add your app in the firewall exceptions, or check you antiVirus.
-
February 17th, 2009, 11:10 AM
#10
Re: Making a VB6 application send an email?
I can only agree here.
I'm using an older SMTP.ocx from ostrosoft and I'm running XP SP3.
I can send emails no problem with this little control.
It also worked perfect when SP2 was on.
I never did no change to any firewall for that matter, and our company is protected by a hardware firewall device.
-
February 17th, 2009, 08:17 PM
#11
Re: Making a VB6 application send an email?
My ISP requires all email be sent from my registered account, and must use port 25. (I have to use a different account when I'm on another provider)
You used to be able to program Outlook to send emails as fast as you could queue them up. Then, there was the delay. Then the OK button clicking program.
You get the idea. Sure, there are 3rd party tools, but they are not good for sending spam
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
|