There are many previous messages relating to generating email messages from Access by using Outlook, but is there a more basic way in which emails can be generated where Outlook is not installed (like the corporate system where I work!!).
I have written a db which identifies staff members who have forgotten to submit paperwork, and I presently print them a report, and send it by snailmail, but want to be able to email them as a batch instead.
Outlook is not installed on the intranet, but Lotus Domino is used instead (not the full client - just the web based version). Is there a way I can generate emails using the SMTP server directly from code?
I have found the following code, but cannot get it to work, does it make sense to you?
Sub STMPSend(strMyDomain As String, _
strEmailServer As String, _
strEmailAddressWithoutDomain As String, _
strWhoToSayThisIsFrom As String, _
strSubject As String, _
strMessageBody As String)
WinSock1.RemoteHost = strEmailServer
WinSock1.RemotePort = 25
WinSock1.Connect
WaitForIt
Select Case Left$(strWSIn, 3)
Case "220"
' connected ok, send HELLO
WinSock1.SendData "HELO " & _
strMyDomain & _
vbCrLf
WaitForIt
WinSock1.SendData "MAIL FROM: " & _
strWhoToSayThisIsFrom & _
vbCrLf
WaitForIt
WinSock1.SendData "RCPT TO: " & _
strWhoToSayThisIsFrom & _
vbCrLf
WaitForIt
WinSock1.SendData "DATA" & vbCrLf & _
"DATE:" & _
Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _
"FROM: " & _
strWhoToSayThisIsFrom & vbCrLf & _
"TO:" & _
Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _
"DATE:" & _
Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _
"SUBJECT: " & _
strSubject & _
vbCrLf & _
strMessageBody & _
vbCrLf & _
"." & vbCrLf
' note: . & vbcrlf terminates the "send"
WaitForIt
' parse and validate the return from the sever
End Select
' tell the server you're done:
WinSock1.SendData "QUIT" & vbCrLf
' and that's it!
WinSock1.Close
End Sub
Private Sub WaitForIt()
WaitingForData = True
While WaitingForData = True
DoEvents
Wend
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Temp As String
Temp = String(bytesTotal, " ")
WinSock1.GetData Temp, vbString
Do
If Right$(Temp, 1) = vbLf Then
Temp = Left$(Temp, Len(Temp) - 1)
End If
Loop While Right$(Temp, 1) = vbLf
strWSIn = Temp
WaitingForData = False
End Sub
I have written a db which identifies staff members who have forgotten to submit paperwork, and I presently print them a report, and send it by snailmail, but want to be able to email them as a batch instead.
Outlook is not installed on the intranet, but Lotus Domino is used instead (not the full client - just the web based version). Is there a way I can generate emails using the SMTP server directly from code?
I have found the following code, but cannot get it to work, does it make sense to you?
Sub STMPSend(strMyDomain As String, _
strEmailServer As String, _
strEmailAddressWithoutDomain As String, _
strWhoToSayThisIsFrom As String, _
strSubject As String, _
strMessageBody As String)
WinSock1.RemoteHost = strEmailServer
WinSock1.RemotePort = 25
WinSock1.Connect
WaitForIt
Select Case Left$(strWSIn, 3)
Case "220"
' connected ok, send HELLO
WinSock1.SendData "HELO " & _
strMyDomain & _
vbCrLf
WaitForIt
WinSock1.SendData "MAIL FROM: " & _
strWhoToSayThisIsFrom & _
vbCrLf
WaitForIt
WinSock1.SendData "RCPT TO: " & _
strWhoToSayThisIsFrom & _
vbCrLf
WaitForIt
WinSock1.SendData "DATA" & vbCrLf & _
"DATE:" & _
Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _
"FROM: " & _
strWhoToSayThisIsFrom & vbCrLf & _
"TO:" & _
Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _
"DATE:" & _
Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _
"SUBJECT: " & _
strSubject & _
vbCrLf & _
strMessageBody & _
vbCrLf & _
"." & vbCrLf
' note: . & vbcrlf terminates the "send"
WaitForIt
' parse and validate the return from the sever
End Select
' tell the server you're done:
WinSock1.SendData "QUIT" & vbCrLf
' and that's it!
WinSock1.Close
End Sub
Private Sub WaitForIt()
WaitingForData = True
While WaitingForData = True
DoEvents
Wend
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Temp As String
Temp = String(bytesTotal, " ")
WinSock1.GetData Temp, vbString
Do
If Right$(Temp, 1) = vbLf Then
Temp = Left$(Temp, Len(Temp) - 1)
End If
Loop While Right$(Temp, 1) = vbLf
strWSIn = Temp
WaitingForData = False
End Sub
Last edited: