-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfMain.frm
234 lines (195 loc) · 6.81 KB
/
fMain.frm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form fMain
Caption = "Dev-Center SMTP Mailer"
ClientHeight = 6150
ClientLeft = 60
ClientTop = 345
ClientWidth = 6915
BeginProperty Font
Name = "Verdana"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 6150
ScaleWidth = 6915
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdExit
Caption = "E&xit"
Height = 495
Left = 3720
TabIndex = 11
Top = 5520
Width = 1215
End
Begin VB.CommandButton cmdSend
Caption = "&Send"
Height = 495
Left = 1920
TabIndex = 10
Top = 5520
Width = 1215
End
Begin VB.TextBox txtMessage
Height = 3165
Left = 120
MultiLine = -1 'True
TabIndex = 8
Top = 2160
Width = 6680
End
Begin VB.TextBox txtSubject
Height = 285
Left = 1800
TabIndex = 6
Text = "SMTP Mailer Feedback"
Top = 1440
Width = 5000
End
Begin VB.TextBox txtToEmail
Height = 285
Left = 1800
TabIndex = 4
Text = "ara@dev-center.com"
Top = 1080
Width = 5000
End
Begin VB.TextBox txtFromEmail
Height = 285
Left = 1800
TabIndex = 2
Top = 720
Width = 5000
End
Begin VB.TextBox txtServerDomain
Height = 285
Left = 1800
TabIndex = 0
Text = "dev-center.com"
Top = 360
Width = 5000
End
Begin MSWinsockLib.Winsock w
Left = 7560
Top = 0
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.Label Label7
Caption = "Message:"
Height = 255
Left = 120
TabIndex = 9
Top = 1920
Width = 1575
End
Begin VB.Label Label6
Caption = "Subject:"
Height = 255
Left = 120
TabIndex = 7
Top = 1440
Width = 1575
End
Begin VB.Label Label5
Caption = "To Email:"
Height = 255
Left = 120
TabIndex = 5
Top = 1080
Width = 1575
End
Begin VB.Label Label3
Caption = "From Email:"
Height = 255
Left = 120
TabIndex = 3
Top = 720
Width = 1575
End
Begin VB.Label Label1
Caption = "Server Domain:"
Height = 255
Left = 120
TabIndex = 1
Top = 360
Width = 1575
End
End
Attribute VB_Name = "fMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'SMTP Mailer
'By Ara Mahdessian (ara@dev-center.com)
'
'go to www.dev-center.com for VB "stuff"
Private Response As String
Sub SendEmail(ServerDomain As String, FromEmail As String, ToEmail As String, Subject As String, Body As String)
w.LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail per program start
If w.State <> sckClosed Then w.Close 'close winsock if open
w.Protocol = sckTCPProtocol 'use tcp/ip protocol
w.RemoteHost = ServerDomain 'server domain
w.RemotePort = 25 '25 is standard smtp port
w.Connect 'connect
WaitForResponse ("220") 'wait for confirmed connection
w.SendData "HELO " & ServerDomain & vbCrLf 'send HELO msg
WaitForResponse ("250") 'wait for response
w.SendData "MAIL FROM: <" & FromEmail & ">" & vbCrLf 'sender's email
WaitForResponse ("250") 'wait for response
w.SendData "RCPT TO: <" & ToEmail & ">" & vbCrLf 'recipient's email
WaitForResponse ("250") 'wait for response
w.SendData ("data" & vbCrLf) 'tell server msg and headers are incoming
WaitForResponse ("354")
w.SendData "From: " & FromEmail & vbCrLf 'name of sender
w.SendData "X-Mailer: Dev-Center SMTP Mailer" & vbCrLf 'name of program [customize it]
w.SendData "To: " & ToEmail & vbCrLf 'name of recipient
w.SendData "Subject: " & Subject & vbCrLf 'subject of email
w.SendData Body & vbCrLf 'send body (message)
w.SendData "." & vbCrLf 'terminate incoming data/headers
WaitForResponse ("250") 'wait for sent mail confirmation
w.SendData "quit" & vbCrLf 'say bye-bye (quit)
WaitForResponse ("221") 'wait for server to log you off - ethics folks
w.Close
MsgBox "Mail sent!", vbExclamation, "SMTP Success"
End Sub
Sub WaitForResponse(ResponseCode As String)
Dim Reply As Integer
Dim Start As Single
Dim Tmr As Single
Start = Timer 'time in case server doesn't respond
While Len(Response) = 0 'do until we get a response from server
Tmr = Start - Timer 'get elapsed time
DoEvents 'let system check for incoming response
If Tmr > 10 Then 'if server is not responding (timed out)
MsgBox "Error:" + vbCrLf + "SMTP service timed out while waiting for response!", vbExclamation, "SMTP Service Error"
Exit Sub
End If
Wend
While Left(Response, 3) <> ResponseCode
DoEvents
If Tmr > 10 Then
MsgBox "Error:" + vbCrLf + "Improper response code received: " + Response + vbCrLf + "Expected code: " + ResponseCode, vbExclamation, "SMTP Service Error"
Exit Sub
End If
Wend
Response = "" 'set response code to blank
End Sub
Private Sub cmdExit_Click()
Unload Me
End
End Sub
Private Sub cmdSend_Click()
SendEmail txtServerDomain, txtFromEmail, txtToEmail, txtSubject, txtMessage
End Sub
Private Sub w_DataArrival(ByVal bytesTotal As Long)
w.GetData Response 'get incoming response
End Sub