Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending a message
Message
From
29/11/1998 07:26:55
 
General information
Forum:
Visual Basic
Category:
Windows API functions
Miscellaneous
Thread ID:
00161327
Message ID:
00162208
Views:
15
>>>I have a VB5 application that needs to send e-mail messages.
>>>
>>>I cannot use Outlook automation neither Notes because not all users have them.
>>>
>>>So I use MAPI (MAPISession and MAPIMessages). It work well on my computer. When people try to distribute my app, they have to configure Windows Messaging and they have difficulties.
>>>
>>>Do you have any other solution?
>>>
>>>PS: The company do not want to buy librairies!!!
>>
>>
>>Well if you use MAPI, the Messaging services or apps must be installed locally or it won't work.
>>
>>Are the users connected all the time to the Internet ?
>>If so, you can send an SMTP email with the Winsock control. Of course you'll have to implement the protocol with VB code but it can easilly be done with the correct RFC document.
>
>Yes, they are always connected to the Internet.
>
>Do you any code sample of that?


I got that code on the net but didn't test it.
Grab the RFC document that explain the SMTP protocol for more info on SMTP. You should be able to find it with no problems on the net.



Private Sub btnSend_Click()
Winsock1.RemoteHost = txHost
Winsock1.RemotePort = 25
Winsock1.Connect
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
' this is the main processing code for
' sending an email message
' the iState variable maintains the current
' state of the protocol exchange so that we
' know what to send next
Dim strData As String
Static iState As Integer
Dim iMsgNum As Integer
Dim szMsg As String
Dim I As Integer

Winsock1.GetData strData, vbString

iMsgNum = Val(Left(strData, InStr(strData, " ")))

Select Case iMsgNum
Case 220 ' initial message
Winsock1.SendData "HELO " & txHost & vbCrLf
txStatus = "Mail Server is ready..."
iState = 1
Case 221
If iState = 999 Then
txStatus = "Disconnected from mail server after error..."
Else
txStatus = "Disconnected from mail server..."
End If
iState = 0

Case 250
Select Case iState
Case 1:
Winsock1.SendData "MAIL FROM:<" & txFrom & ">" & vbCrLf
Debug.Print "MAIL FROM:<" & txFrom & ">" & vbCrLf
txStatus = "Sending FROM command..."
iState = 2

Case 2:
Winsock1.SendData "RCPT TO:<" & txTo & ">" & vbCrLf
Debug.Print "RCPT TO:<" & txTo & ">" & vbCrLf
txStatus = "Sending RCPT command..."
iState = 3

Case 3:
Winsock1.SendData "DATA" & vbCrLf
Debug.Print "DATA" & vbCrLf
txStatus = "Sending DATA command..."
iState = 4

Case 5:
Winsock1.SendData "QUIT" & vbCrLf
Debug.Print "QUIT" & vbCrLf
txStatus = "Sending Quit command to disconnecting from mail server..."
iState = 6
Winsock1.Close
End Select

Case 354
iState = 5
szMsg = txMessage
txStatus = "Sending mail message data..."
Winsock1.SendData "Subject: " & txSubject & vbCrLf
While szMsg <> ""
Winsock1.SendData Left(szMsg, InStr(szMsg, Chr(10)))
Debug.Print "Sending:" & Left(szMsg, InStr(szMsg, Chr(10)))
szMsg = Mid(szMsg, InStr(szMsg, Chr(10)) + 1)
Wend
Winsock1.SendData "." & vbCrLf

Case 500 To 599
Winsock1.SendData "QUIT" & vbCrLf
txStatus = "Error sending mail..."
Debug.Print "Error sending mail... quitting..."
iState = 999

End Select

End Sub
Guy Barrette, MCSD
============
Blog http://weblogs.asp.net/guybarrette
Microsoft Regional Director, Montreal, Canada www.microsoft.com/rd
MVP, ASP.NET http://mvp.support.microsoft.com/
President, Montreal Visual Studio User Group www.guvsm.net
INETA Regional Rep for Quebec www.ineta.org
UniversalThread Magazine Columnist (.NET Books Review Column) www.utmag.com
Tech Chair French Track, DevTeach 2004 & 2005 www.devteach.com
Business Architect, Microsoft Team - Nurun Inc www.nurun.com
XBox Live Gamer Tag: Slomo QC CA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform