Monstric » 08.02.2006 (Ср) 10:23
Sub SendEmail(MailServerName As String, FromName As String, FromEmailAddress As String, ToName As String, ToEmailAddress As String, EmailSubject As String, EmailBodyOfMessage As String)
Dim First As String
Dim Second As String
Dim Third As String
Dim Fourth As String
Dim Sixth As String
Dim Seventh As String
Dim Ninht As String
Dim Eghth As String
Form1.Winsock1.LocalPort = 0
Form1.Winsock1.Close
DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
First = "mail from:" + Chr(32) + FromEmailAddress + vbCrLf
Second = "rcpt to:" + Chr(32) + ToEmailAddress + vbCrLf
Third = "Date:" + Chr(32) + DateNow + vbCrLf
Fourth = "From:" + Chr(32) + FromName + vbCrLf
Fifth = "To:" + Chr(32) + ToNametxt + vbCrLf
Sixth = "Subject:" + Chr(32) + EmailSubject + vbCrLf
Seventh = EmailBodyOfMessage + vbCrLf
Ninth = "X-MailerMyMail v1.0" + vbCrLf 'придумайте что-нибудь своё
Eighth = Fourth + Third + Ninth + Fifth + Sixth
Form1.Winsock1.Protocol = 0
Form1.Winsock1.RemoteHost = MailServerName
Form1.Winsock1.RemotePort = 25
Form1.Winsock1.Connect
WaitFor ("220")
Form1.Winsock1.SendData ("HELO" & vbCrLf)
WaitFor ("250")
Form1.Winsock1.SendData (First)
WaitFor ("250")
Form1.Winsock1.SendData (Second)
WaitFor ("250")
Form1.Winsock1.SendData ("data" + vbCrLf)
WaitFor ("354")
Form1.Winsock1.SendData (Eighth + vbCrLf)
Form1.Winsock1.SendData (Seventh + vbCrLf)
Form1.Winsock1.SendData ("." + vbCrLf)
WaitFor ("250")
Form1.Winsock1.SendData ("quit" + vbCrLf)
WaitFor ("221")
Form1.Winsock1.Close
End Sub
Sub WaitFor(ResponseCode As String)
Start = Timer ' Time event so won't get stuck in loop
While Len(Response) = 0
Tmr = Start - Timer
DoEvents ' Let System keep checking for incoming response **IMPORTANT**
If Tmr > 50 Then ' Время в секундах на ожидание
MsgBox "Превышение периода ожидания", vbCritical
Exit Sub
End If
Wend
While Left(Response, 3) <> ResponseCode
DoEvents
If Tmr > 50 Then
MsgBox "Неправильный код", vbCritical
Exit Sub
End If
Wend
Response = ""
End Sub
Так как времени на прогу мало, то пришлось взять с инета готовый пример!
Семь бед - один RESET!