Send e-mail via visual basic (udenom Outlook)
HejsaJeg har fundet følgende kode på nettet, men mangler lidt "setup" i VBA for at få det til at virke. Nogen, der kan give en hjælpende hånd? - Hvordan får jeg VB til at benytte winsock (.ocx)?
'**************************************
' Name: a The easiest way to send mail!
' Description:I have seen some e-mail st
' uff on this site, but all are so freakin
' complicated. This is simple and VERY eas
' y to use!
' By: Dustin Davis
'
'This code is copyrighted and has ' limited warranties.Please see http://w
' ww.Planet-Source-Code.com/xq/ASP/txtCode
' Id.5325/lngWId.1/qx/vb/scripts/ShowCode.
' htm 'for details. '**************************************
Dim sRes As String
Private Sub Command1_Click()
Winsock1.RemotePort = 25
Winsock1.RemoteHost = your_mail_server_here 'use your mail server
Winsock1.Connect
Do Until Winsock1.State = 7 '7=connected
DoEvents
Loop
sRes = "0"
Winsock1.SendData "MAIL FROM: " & your_email_here & vbCrLf
Do Until sRes = "250"
DoEvents
Loop
sRes = "0"
Winsock1.SendData "RCPT TO: " & someone_email_here & vbCrLf
Do Until sRes = "250"
DoEvents
Loop
sRes = "0"
Winsock1.SendData "DATA" & vbCrLf
Do Until sRes = "354"
DoEvents
Loop
Winsock1.SendData "FROM: " & your_name_here & vbCrLf
Winsock1.SendData "SUBJECT: " & subject_here & vbCrLf
Winsock1.SendData Text1.Text & vbCrLf & "." & vbCrLf
Do Until sRes = "250"
DoEvents
Loop
Winsock1.Close
MsgBox "Mail sent!"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
Dim Length As Long
Winsock1.GetData Data
Length = Len(Data)
sRes = Left$(Data, 3)
End Sub
(http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=5325&lngWId=1)
