If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#11
|
|||
|
|||
I am able to communicate with my mail server on port 25. However, how do you
end the DATA command??? In the Telnet session after I type in "Data test", I get a response back saying... 354 Start mail input; end with CRLF.CRLF After I type in the body of the message, I cannot end that line. I've tried typing in exactly what it says and various other things but none seem to work. We are using an Exchange 2000 server. Any ideas?? Thanks, Brad My FTP client is saying to end with "Alex Ivanov" wrote in message ... I accidentally swithced "from" and "to" this caused rejection from my isp. This is the corrected code that works. If you need to send the mail to external clients, you will need either to add an authentication code or set the RemoteHost property to their mail servers before sending (unless you have an 'open proxy' allowing mail forwarding). HTH Option Explicit Private Sub Form_Load() With Winsock1 .RemoteHost = "test.net" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock1.BytesReceived) Winsock1.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock1.SendData "helo nothing.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then Winsock1.SendData "mail from: test@test" & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then Winsock1.SendData "rcpt to: " & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: My Subject" & vbCrLf _ & "From: Me" & vbCrLf & vbCrLf _ & "Your data goes here." & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail Sent" End Select End Sub -- Please reply to NG only. This email is not monitored. Alex. "Alex Ivanov" wrote in message ... This is a barebone code with no authentication and no encryption. Some mail servers may accept similar requests other not. My home ISP's mail server silently ignores the email sent this way though it seems that send succeeds. Our company's Exchange server is happy to work with it if the mail is sent to internal recipients. Anyway, you can try. |
#12
|
|||
|
|||
hi Brad,
Brad Pears wrote: 354 Start mail input; end with CRLF.CRLF After I type in the body of the message, I cannot end that line. I've tried typing in exactly what it says and various other things but none seem to work. vbCrLf & "." & vbCrLf = Chr(13) & Chr(10) & "." Chr(13) & Chr(10) mfG -- stefan -- |
#13
|
|||
|
|||
I am having a heck of a time with this - implementing it into my project...
I was able to get it to work standalone by having all the code on the same screen where I inserted the winsock control... But I cannot seem to get it to work properly when the code to send the mail is in a procedure in a module... Here's the scoop... On one of my forms, I added the Winsock control and renamed it to Winsock1. However, it's not actually on this form where I have placed the code to send the email. Instead - I placed the code inside a procedure that exists in a module. When the user clicks a command button on this form, it runs the on-click event which in turn calls a "SendMail" procedure to do the job. So, in my module, in the declarations section, I have declared ... public winsock1 as winsock. Then I have my called procedure as follows... Public Sub SendMail() With Winsock1 .RemoteHost = "true3" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Then in this same module I have placed the other code to actually send the email (shown below...) The problem is that when the procedure is called to connect to my mail server I get the following error everytime ... "Object variable or with block variable not set" and when I click the Debug button, the code that is highlited is the .remotehost = "true3" line. What am I missing? Is my winsock control not being defined properly somewhere? Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer 'Dim strMailTO As String 'Dim strMailSubject As String 'Dim strBody As String Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock2.BytesReceived) Winsock2.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock2.SendData "helo truenorthloghomes.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then ' winsock1.SendData getMailFrom(CurrentUser()) & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then ' winsock1.SendData "rcpt to: craigd" & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: " & strSubject & vbCrLf _ & "From: " & getMailFromFullName(CurrentUser()) & vbCrLf & vbCrLf _ & strBody & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail message successfully sent to " & strTo End Select End Sub "Alex Ivanov" wrote in message ... Yes, that basically all. Yo will need to set RemoteHost property to your mail server address and make sure the "rcpt to:" line contains a valid address recognized by that server otherwise you may need to implement an authentication protocol. -- Please reply to NG only. This email is not monitored. Alex. "Brad Pears" wrote in message ... So to test this, do I just add the ActiveX Microsoft Winsock version 6 control to my form and rename the winsock control to "winsock1"?? When I add the control it's named something completely different... (ActiveXctl1) Should I be worried about that? Not sure how to test this... Thanks, Brad "Alex Ivanov" wrote in message ... I accidentally swithced "from" and "to" this caused rejection from my isp. This is the corrected code that works. If you need to send the mail to external clients, you will need either to add an authentication code or set the RemoteHost property to their mail servers before sending (unless you have an 'open proxy' allowing mail forwarding). HTH Option Explicit Private Sub Form_Load() With Winsock1 .RemoteHost = "test.net" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock1.BytesReceived) Winsock1.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock1.SendData "helo nothing.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then Winsock1.SendData "mail from: test@test" & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then Winsock1.SendData "rcpt to: " & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: My Subject" & vbCrLf _ & "From: Me" & vbCrLf & vbCrLf _ & "Your data goes here." & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail Sent" End Select End Sub -- Please reply to NG only. This email is not monitored. Alex. "Alex Ivanov" wrote in message ... This is a barebone code with no authentication and no encryption. Some mail servers may accept similar requests other not. My home ISP's mail server silently ignores the email sent this way though it seems that send succeeds. Our company's Exchange server is happy to work with it if the mail is sent to internal recipients. Anyway, you can try. |
#14
|
|||
|
|||
Thanks for that!
"stefan hoffmann" wrote in message ... hi Brad, Brad Pears wrote: 354 Start mail input; end with CRLF.CRLF After I type in the body of the message, I cannot end that line. I've tried typing in exactly what it says and various other things but none seem to work. vbCrLf & "." & vbCrLf = Chr(13) & Chr(10) & "." Chr(13) & Chr(10) mfG -- stefan -- |
#15
|
|||
|
|||
Brad,
in order to use Winsock control without form - you have to create new instance, but this is posible in VB only, because you have to add license. this is not possible in Access. so in access you have to insert in a form in order to have it instance created. form can be hidden, if you dont want to show it HTH -- Alex Dybenko (MVP) http://Alex.Dybenko.com http://www.PointLtd.com "Brad Pears" wrote in message ... I am having a heck of a time with this - implementing it into my project... I was able to get it to work standalone by having all the code on the same screen where I inserted the winsock control... But I cannot seem to get it to work properly when the code to send the mail is in a procedure in a module... Here's the scoop... On one of my forms, I added the Winsock control and renamed it to Winsock1. However, it's not actually on this form where I have placed the code to send the email. Instead - I placed the code inside a procedure that exists in a module. When the user clicks a command button on this form, it runs the on-click event which in turn calls a "SendMail" procedure to do the job. So, in my module, in the declarations section, I have declared ... public winsock1 as winsock. Then I have my called procedure as follows... Public Sub SendMail() With Winsock1 .RemoteHost = "true3" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Then in this same module I have placed the other code to actually send the email (shown below...) The problem is that when the procedure is called to connect to my mail server I get the following error everytime ... "Object variable or with block variable not set" and when I click the Debug button, the code that is highlited is the .remotehost = "true3" line. What am I missing? Is my winsock control not being defined properly somewhere? Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer 'Dim strMailTO As String 'Dim strMailSubject As String 'Dim strBody As String Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock2.BytesReceived) Winsock2.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock2.SendData "helo truenorthloghomes.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then ' winsock1.SendData getMailFrom(CurrentUser()) & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then ' winsock1.SendData "rcpt to: craigd" & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: " & strSubject & vbCrLf _ & "From: " & getMailFromFullName(CurrentUser()) & vbCrLf & vbCrLf _ & strBody & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail message successfully sent to " & strTo End Select End Sub "Alex Ivanov" wrote in message ... Yes, that basically all. Yo will need to set RemoteHost property to your mail server address and make sure the "rcpt to:" line contains a valid address recognized by that server otherwise you may need to implement an authentication protocol. -- Please reply to NG only. This email is not monitored. Alex. "Brad Pears" wrote in message ... So to test this, do I just add the ActiveX Microsoft Winsock version 6 control to my form and rename the winsock control to "winsock1"?? When I add the control it's named something completely different... (ActiveXctl1) Should I be worried about that? Not sure how to test this... Thanks, Brad "Alex Ivanov" wrote in message ... I accidentally swithced "from" and "to" this caused rejection from my isp. This is the corrected code that works. If you need to send the mail to external clients, you will need either to add an authentication code or set the RemoteHost property to their servers before sending (unless you have an 'open proxy' allowing mail forwarding). HTH Option Explicit Private Sub Form_Load() With Winsock1 .RemoteHost = "test.net" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock1.BytesReceived) Winsock1.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock1.SendData "helo nothing.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then Winsock1.SendData "mail from: test@test" & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then Winsock1.SendData "rcpt to: " & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: My Subject" & vbCrLf _ & "From: Me" & vbCrLf & vbCrLf _ & "Your data goes here." & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail Sent" End Select End Sub -- Please reply to NG only. This email is not monitored. Alex. "Alex Ivanov" wrote in message ... This is a barebone code with no authentication and no encryption. Some mail servers may accept similar requests other not. My home ISP's mail server silently ignores the email sent this way though it seems that send succeeds. Our company's Exchange server is happy to work with it if the mail is sent to internal recipients. Anyway, you can try. |
#16
|
|||
|
|||
I was able to get this working but I have found that I will sometimes get an
error... Runtime Error: 40006 "Wrong protocol or connection state for the requested transaction or request" on the "Winsock1.GetData buf, vbString" line in the winsock1_DataArrival event. If I try to send a couple of emails back to back. Each time an email is sent, there is code that closes the connection - but it appears that maybe it is not being closed properly?? Have you seen this before and do you have any ideas on how to proceed? Obviously this will not work in it's current state. Thanks, Brad "stefan hoffmann" wrote in message ... hi Brad, Brad Pears wrote: 354 Start mail input; end with CRLF.CRLF After I type in the body of the message, I cannot end that line. I've tried typing in exactly what it says and various other things but none seem to work. vbCrLf & "." & vbCrLf = Chr(13) & Chr(10) & "." Chr(13) & Chr(10) mfG -- stefan -- |
#17
|
|||
|
|||
I was able to get this working but I have found that I will sometimes get an
error... Runtime Error: 40006 "Wrong protocol or connection state for the requested transaction or request" on the "Winsock1.GetData buf, vbString" line in the winsock1_DataArrival event. If I try to send a couple of emails back to back. Each time an email is sent, there is code that closes the connection - but it appears that maybe it is not being closed properly?? Have you seen this before and do you have any ideas on how to proceed? Obviously this will not work in it's current state. Thanks, Brad "Alex Dybenko" wrote in message ... Brad, in order to use Winsock control without form - you have to create new instance, but this is posible in VB only, because you have to add license. this is not possible in Access. so in access you have to insert in a form in order to have it instance created. form can be hidden, if you dont want to show it HTH -- Alex Dybenko (MVP) http://Alex.Dybenko.com http://www.PointLtd.com "Brad Pears" wrote in message ... I am having a heck of a time with this - implementing it into my project... I was able to get it to work standalone by having all the code on the same screen where I inserted the winsock control... But I cannot seem to get it to work properly when the code to send the mail is in a procedure in a module... Here's the scoop... On one of my forms, I added the Winsock control and renamed it to Winsock1. However, it's not actually on this form where I have placed the code to send the email. Instead - I placed the code inside a procedure that exists in a module. When the user clicks a command button on this form, it runs the on-click event which in turn calls a "SendMail" procedure to do the job. So, in my module, in the declarations section, I have declared ... public winsock1 as winsock. Then I have my called procedure as follows... Public Sub SendMail() With Winsock1 .RemoteHost = "true3" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Then in this same module I have placed the other code to actually send the email (shown below...) The problem is that when the procedure is called to connect to my mail server I get the following error everytime ... "Object variable or with block variable not set" and when I click the Debug button, the code that is highlited is the .remotehost = "true3" line. What am I missing? Is my winsock control not being defined properly somewhere? Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer 'Dim strMailTO As String 'Dim strMailSubject As String 'Dim strBody As String Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock2.BytesReceived) Winsock2.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock2.SendData "helo truenorthloghomes.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then ' winsock1.SendData getMailFrom(CurrentUser()) & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then ' winsock1.SendData "rcpt to: craigd" & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: " & strSubject & vbCrLf _ & "From: " & getMailFromFullName(CurrentUser()) & vbCrLf & vbCrLf _ & strBody & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail message successfully sent to " & strTo End Select End Sub "Alex Ivanov" wrote in message ... Yes, that basically all. Yo will need to set RemoteHost property to your mail server address and make sure the "rcpt to:" line contains a valid address recognized by that server otherwise you may need to implement an authentication protocol. -- Please reply to NG only. This email is not monitored. Alex. "Brad Pears" wrote in message ... So to test this, do I just add the ActiveX Microsoft Winsock version 6 control to my form and rename the winsock control to "winsock1"?? When I add the control it's named something completely different... (ActiveXctl1) Should I be worried about that? Not sure how to test this... Thanks, Brad "Alex Ivanov" wrote in message ... I accidentally swithced "from" and "to" this caused rejection from my isp. This is the corrected code that works. If you need to send the mail to external clients, you will need either to add an authentication code or set the RemoteHost property to their servers before sending (unless you have an 'open proxy' allowing forwarding). HTH Option Explicit Private Sub Form_Load() With Winsock1 .RemoteHost = "test.net" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock1.BytesReceived) Winsock1.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock1.SendData "helo nothing.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then Winsock1.SendData "mail from: test@test" & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then Winsock1.SendData "rcpt to: " & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: My Subject" & vbCrLf _ & "From: Me" & vbCrLf & vbCrLf _ & "Your data goes here." & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail Sent" End Select End Sub -- Please reply to NG only. This email is not monitored. Alex. "Alex Ivanov" wrote in message ... This is a barebone code with no authentication and no encryption. Some mail servers may accept similar requests other not. My home ISP's mail server silently ignores the email sent this way though it seems that send succeeds. Our company's Exchange server is happy to work with it if the mail is sent to internal recipients. Anyway, you can try. |
#18
|
|||
|
|||
Perhaps what you're experience is due to the race of signals. You may try to
add a static boolean variable to the procedure and set it to true when your mailer starts and false when it finishes. Then check this var upon entering the code and if previous send command is still running raise an error or do something else to prevent the race condition. And, yes, clear the c250 variable in case 221 - it is static also. HTH -- Please reply to NG only. This email is not monitored. Alex. "Brad Pears" wrote in message ... I was able to get this working but I have found that I will sometimes get an error... Runtime Error: 40006 "Wrong protocol or connection state for the requested transaction or request" on the "Winsock1.GetData buf, vbString" line in the winsock1_DataArrival event. If I try to send a couple of emails back to back. Each time an email is sent, there is code that closes the connection - but it appears that maybe it is not being closed properly?? Have you seen this before and do you have any ideas on how to proceed? Obviously this will not work in it's current state. Thanks, Brad "Alex Dybenko" wrote in message ... Brad, in order to use Winsock control without form - you have to create new instance, but this is posible in VB only, because you have to add license. this is not possible in Access. so in access you have to insert in a form in order to have it instance created. form can be hidden, if you dont want to show it HTH -- Alex Dybenko (MVP) http://Alex.Dybenko.com http://www.PointLtd.com "Brad Pears" wrote in message ... I am having a heck of a time with this - implementing it into my project... I was able to get it to work standalone by having all the code on the same screen where I inserted the winsock control... But I cannot seem to get it to work properly when the code to send the mail is in a procedure in a module... Here's the scoop... On one of my forms, I added the Winsock control and renamed it to Winsock1. However, it's not actually on this form where I have placed the code to send the email. Instead - I placed the code inside a procedure that exists in a module. When the user clicks a command button on this form, it runs the on-click event which in turn calls a "SendMail" procedure to do the job. So, in my module, in the declarations section, I have declared ... public winsock1 as winsock. Then I have my called procedure as follows... Public Sub SendMail() With Winsock1 .RemoteHost = "true3" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Then in this same module I have placed the other code to actually send the email (shown below...) The problem is that when the procedure is called to connect to my mail server I get the following error everytime ... "Object variable or with block variable not set" and when I click the Debug button, the code that is highlited is the .remotehost = "true3" line. What am I missing? Is my winsock control not being defined properly somewhere? Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer 'Dim strMailTO As String 'Dim strMailSubject As String 'Dim strBody As String Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock2.BytesReceived) Winsock2.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock2.SendData "helo truenorthloghomes.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then ' winsock1.SendData getMailFrom(CurrentUser()) & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then ' winsock1.SendData "rcpt to: craigd" & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: " & strSubject & vbCrLf _ & "From: " & getMailFromFullName(CurrentUser()) & vbCrLf & vbCrLf _ & strBody & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail message successfully sent to " & strTo End Select End Sub "Alex Ivanov" wrote in message ... Yes, that basically all. Yo will need to set RemoteHost property to your mail server address and make sure the "rcpt to:" line contains a valid address recognized by that server otherwise you may need to implement an authentication protocol. -- Please reply to NG only. This email is not monitored. Alex. "Brad Pears" wrote in message ... So to test this, do I just add the ActiveX Microsoft Winsock version 6 control to my form and rename the winsock control to "winsock1"?? When I add the control it's named something completely different... (ActiveXctl1) Should I be worried about that? Not sure how to test this... Thanks, Brad "Alex Ivanov" wrote in message ... I accidentally swithced "from" and "to" this caused rejection from my isp. This is the corrected code that works. If you need to send the mail to external clients, you will need either to add an authentication code or set the RemoteHost property to their servers before sending (unless you have an 'open proxy' allowing forwarding). HTH Option Explicit Private Sub Form_Load() With Winsock1 .RemoteHost = "test.net" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock1.BytesReceived) Winsock1.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock1.SendData "helo nothing.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then Winsock1.SendData "mail from: test@test" & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then Winsock1.SendData "rcpt to: " & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: My Subject" & vbCrLf _ & "From: Me" & vbCrLf & vbCrLf _ & "Your data goes here." & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail Sent" End Select End Sub -- Please reply to NG only. This email is not monitored. Alex. "Alex Ivanov" wrote in message ... This is a barebone code with no authentication and no encryption. Some mail servers may accept similar requests other not. My home ISP's mail server silently ignores the email sent this way though it seems that send succeeds. Our company's Exchange server is happy to work with it if the mail is sent to internal recipients. Anyway, you can try. |
#19
|
|||
|
|||
What exactly do you mean by a race of signals?
Also what exactly does declaring a variable of static enable vs declaring it as public? "Alex Ivanov" wrote in message ... Perhaps what you're experience is due to the race of signals. You may try to add a static boolean variable to the procedure and set it to true when your mailer starts and false when it finishes. Then check this var upon entering the code and if previous send command is still running raise an error or do something else to prevent the race condition. And, yes, clear the c250 variable in case 221 - it is static also. HTH -- Please reply to NG only. This email is not monitored. Alex. "Brad Pears" wrote in message ... I was able to get this working but I have found that I will sometimes get an error... Runtime Error: 40006 "Wrong protocol or connection state for the requested transaction or request" on the "Winsock1.GetData buf, vbString" line in the winsock1_DataArrival event. If I try to send a couple of emails back to back. Each time an email is sent, there is code that closes the connection - but it appears that maybe it is not being closed properly?? Have you seen this before and do you have any ideas on how to proceed? Obviously this will not work in it's current state. Thanks, Brad "Alex Dybenko" wrote in message ... Brad, in order to use Winsock control without form - you have to create new instance, but this is posible in VB only, because you have to add license. this is not possible in Access. so in access you have to insert in a form in order to have it instance created. form can be hidden, if you dont want to show it HTH -- Alex Dybenko (MVP) http://Alex.Dybenko.com http://www.PointLtd.com "Brad Pears" wrote in message ... I am having a heck of a time with this - implementing it into my project... I was able to get it to work standalone by having all the code on the same screen where I inserted the winsock control... But I cannot seem to get it to work properly when the code to send the mail is in a procedure in a module... Here's the scoop... On one of my forms, I added the Winsock control and renamed it to Winsock1. However, it's not actually on this form where I have placed the code to send the email. Instead - I placed the code inside a procedure that exists in a module. When the user clicks a command button on this form, it runs the on-click event which in turn calls a "SendMail" procedure to do the job. So, in my module, in the declarations section, I have declared ... public winsock1 as winsock. Then I have my called procedure as follows... Public Sub SendMail() With Winsock1 .RemoteHost = "true3" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Then in this same module I have placed the other code to actually send the email (shown below...) The problem is that when the procedure is called to connect to my server I get the following error everytime ... "Object variable or with block variable not set" and when I click the Debug button, the code that is highlited is the .remotehost = "true3" line. What am I missing? Is my winsock control not being defined properly somewhere? Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer 'Dim strMailTO As String 'Dim strMailSubject As String 'Dim strBody As String Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock2.BytesReceived) Winsock2.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock2.SendData "helo truenorthloghomes.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then ' winsock1.SendData getMailFrom(CurrentUser()) & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then ' winsock1.SendData "rcpt to: craigd" & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: " & strSubject & vbCrLf _ & "From: " & getMailFromFullName(CurrentUser()) & vbCrLf & vbCrLf _ & strBody & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail message successfully sent to " & strTo End Select End Sub "Alex Ivanov" wrote in message ... Yes, that basically all. Yo will need to set RemoteHost property to your mail server address and make sure the "rcpt to:" line contains a valid address recognized by that server otherwise you may need to implement an authentication protocol. -- Please reply to NG only. This email is not monitored. Alex. "Brad Pears" wrote in message ... So to test this, do I just add the ActiveX Microsoft Winsock version 6 control to my form and rename the winsock control to "winsock1"?? When I add the control it's named something completely different... (ActiveXctl1) Should I be worried about that? Not sure how to test this... Thanks, Brad "Alex Ivanov" wrote in message ... I accidentally swithced "from" and "to" this caused rejection from my isp. This is the corrected code that works. If you need to send the mail to external clients, you will need either to add an authentication code or set the RemoteHost property to their servers before sending (unless you have an 'open proxy' allowing forwarding). HTH Option Explicit Private Sub Form_Load() With Winsock1 .RemoteHost = "test.net" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock1.BytesReceived) Winsock1.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock1.SendData "helo nothing.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then Winsock1.SendData "mail from: test@test" & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then Winsock1.SendData "rcpt to: " & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: My Subject" & vbCrLf _ & "From: Me" & vbCrLf & vbCrLf _ & "Your data goes here." & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail Sent" End Select End Sub -- Please reply to NG only. This email is not monitored. Alex. "Alex Ivanov" wrote in message ... This is a barebone code with no authentication and no encryption. Some mail servers may accept similar requests other not. My home ISP's mail server silently ignores the email sent this way though it seems that send succeeds. Our company's Exchange server is happy to work with it if the mail is sent to internal recipients. Anyway, you can try. |
#20
|
|||
|
|||
"Brad Pears" , haber iletisinde şunları ... So to test this, do I just add the Microsoft Winsock control to my form and rename the winsock control to "winsock1"?? When I add the control it's named something completely different... Should I be worried about that? Not sure how to test this... Thanks, Brad "Alex Ivanov" wrote in message ... I accidentally swithced "from" and "to" this caused rejection from my isp. This is the corrected code that works. If you need to send the mail to external clients, you will need either to add an authentication code or set the RemoteHost property to their mail servers before sending (unless you have an 'open proxy' allowing mail forwarding). HTH Option Explicit Private Sub Form_Load() With Winsock1 .RemoteHost = "test.net" .RemotePort = 25 .Protocol = sckTCPProtocol .Connect End With End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim buf As String Dim retcode As Integer Static c250 As Integer Dim numOfRecipients numOfRecipients = 1 buf = Space(Winsock1.BytesReceived) Winsock1.GetData buf, vbString Debug.Print buf retcode = Val(Left(buf, 3)) Select Case retcode Case 220 Winsock1.SendData "helo nothing.com" & vbCrLf c250 = 0 Case 250 If c250 = 0 Then Winsock1.SendData "mail from: test@test" & vbCrLf c250 = c250 + 1 ElseIf c250 numOfRecipients + 1 Then Winsock1.SendData "rcpt to: " & vbCrLf c250 = c250 + 1 ElseIf c250 = numOfRecipients + 1 Then Winsock1.SendData "data" & vbCrLf c250 = c250 + 1 Else Winsock1.SendData "quit" & vbCrLf End If Case 354 Winsock1.SendData "Subject: My Subject" & vbCrLf _ & "From: Me" & vbCrLf & vbCrLf _ & "Your data goes here." & vbCrLf & "." & vbCrLf Case 221 Winsock1.Close MsgBox "Mail Sent" End Select End Sub -- Please reply to NG only. This email is not monitored. Alex. "Alex Ivanov" wrote in message ... This is a barebone code with no authentication and no encryption. Some mail servers may accept similar requests other not. My home ISP's mail server silently ignores the email sent this way though it seems that send succeeds. Our company's Exchange server is happy to work with it if the mail is sent to internal recipients. Anyway, you can try. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
using the WInsock control.... | Brad Pears | Using Forms | 0 | November 10th, 2004 03:04 PM |
How can I move the focus to a control on a subform? | Brandon | General Discussion | 7 | July 17th, 2004 01:39 AM |
Access Calendar | lost | General Discussion | 2 | July 7th, 2004 04:58 AM |
How to assign value to a report control? | Peter | General Discussion | 3 | June 29th, 2004 11:17 AM |
Inserting a User Control in PowerPoint | Aaron | Powerpoint | 0 | June 22nd, 2004 11:52 PM |