smtp

  • Thread starter igg via AccessMonster.com
  • Start date
I

igg via AccessMonster.com

i need access 2003 form to send email using smtp protocol. It should get the
email sendto: addresses from a table of recipients list. any codes, examples,
etc.?.
 
B

biganthony via AccessMonster.com

igg,

I am not a developer and am no way as capable as any of the experts that will
answer you, but I use Blat.exe to send reports using SMTP. You can download
the exe from www.blat.net and place blat.exe in the same folder as your
application. I use it to email reports that have been converted to pdf.

The following websites are what I used and you may get some ideas from them.

http://www.blat.net/

http://www.blat.net/newdocs/MSAccess_class.html

http://www.freevbcode.com/ShowCode.Asp?ID=109

http://www.rogersaccesslibrary.com/forum/forum_posts.asp?TID=149

There sia lso a blat usergroup on Yahoo groups.

Tony Teows also has a page at: http://www.granite.ab.ca/access/email.htm

Code that I have used is listed below. I use a function written by Francisco
H Tapia and it is in the sample database downloaded from Rogers Access
Library listed above ( if I remember correctly).

The function below is called like this:

SendBlatMail strFromEmail, strFromMail, strToMail, strSubject, strMessage,
strMessageAttachment


Function SendBlatMail(strFromName As String, strFrom As String, strRecipient
As Variant, strSubject As String, strBody As String, Optional
strSavedFileName As Variant)
'-----------------------------------------------------------------------------
----------
' Procedure : SendBlatMail
' DateTime : 2002-12-27 08:27am
' Author : Francisco H Tapia
' Variables : strFromName (email Name), strFrom (email address), strRecipient
(list of address separated by a comma ",")
' strSubject (string), strBody (string), strAttachment (full path
to attachments separated by a comma ",")
' Purpose : Replacement send email function, this function makes a full
call to the BLAT utility.
'-----------------------------------------------------------------------------
----------
'
Dim strRecipientList As String
Dim strAttachmentList As String
Dim strMail As String
Dim i As Integer
Dim strOrganisation As String
Dim strResponse As String
Dim strHost As String

On Error GoTo SendBlatMail_Error
strOrganisation = "Organisation Name"
strHost = "Host name"
If IsArray(strRecipient) Then
For i = LBound(strRecipient) To UBound(strRecipient)
If Len(strRecipientList) = 0 Then
strRecipientList = "-t " & Chr(34) & strRecipient(i)
Else
strRecipientList = strRecipientList & " , " & strRecipient(i)
End If
Next
strRecipientList = strRecipientList & Chr(34)
Else
strRecipientList = "-t " & Chr(34) & strRecipient & Chr(34)
End If
If Not IsMissing(strSavedFileName) And Not IsEmpty(strSavedFileName) Then
If IsArray(strSavedFileName) Then
For i = LBound(strSavedFileName) To UBound(strSavedFileName)
strAttachmentList = " -attach " & Chr(34) & strSavedFileName
(i)
Next
strAttachmentList = strAttachmentList & Chr(34)
Else
strAttachmentList = " -attach " & Chr(34) & strSavedFileName &
Chr(34)
End If
End If
strMail = " " & strAttachmentList
If strMail <> "" Then
strMail = strMail & " -subject " & Chr(34) & strSubject & Chr(34)
Else
strMail = " -subject " & Chr(34) & strSubject & Chr(34)
End If
strMail = strMail & " " & strRecipientList
strMail = strMail & " -f " & Chr(34) & strFrom & Chr(34)
strMail = strMail & " -from " & Chr(34) & strFromName & Chr(34)
strMail = strMail & " -org " & Chr(34) & strOrganisation & Chr(34)
strMail = strMail & " -HostName " & Chr(34) & strHost & Chr(34)
strMail = strMail & " -x " & Chr(34) & "X-INFO: BLAT Message" & Chr(34)
strMail = strMail & " -noh"
strMail = strMail & " -noh2"
strMail = strMail & " -log " & Chr(34) & ShortPath(CurrentProject.path &
"\BlatLOG.txt") & Chr(34)
'ADD YOUR SMTP SERVER IP AND USER ID AND PASSWORD HERE SO THAT THE
MAIL ACTUALLY SENDS.
strMail = strMail & " -server " & Chr(34) & "SMTP SERVER IP" & Chr(34)
strMail = strMail & " -port 25"
strMail = strMail & " -u " & Chr(34) & "SMTP Username" & Chr(34)
strMail = strMail & " -pw " & Chr(34) & "SMTP Password" & Chr(34)
strMail = strMail & " -try 3"
'strMail = strMail & " -debug"
strMail = strMail & " -timestamp"
'Location of BLAT.
Call ShellWait(CurrentProject.path & "\blat.exe" & " - " & strMail & " -
body " & Chr(34) & strBody & Chr(34), vbHide)
i = FreeFile
Open ShortPath(CurrentProject.path & "\BlatLOG.txt") For Input As i
While Not EOF(i)
Input #i, strResponse
If InStr(1, strResponse, "The mail server", vbTextCompare) = 1 Or _
InStr(1, strResponse, "Have you", vbTextCompare) = 1 Then
MsgBox strResponse, vbOKOnly + vbExclamation, "Email Failed!"
End If
Wend
Close #i
Kill ShortPath(CurrentProject.path & "\BLATLOG.txt")

SendBlatMail_Exit:
On Error Resume Next

On Error GoTo 0
DoCmd.Hourglass False
Exit Function

SendBlatMail_Error:
If Err.Number = 2501 Then
Resume Next
Else
Select Case Err
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure SendBlatMail of Module modBlat", vbExclamation + vbOKOnly, "Help."
End Select
End If
Resume SendBlatMail_Exit
Resume

End Function

*********************************

Hope that helps you.
Anthony
 
I

igg via AccessMonster.com

thanks for your help.
igg,

I am not a developer and am no way as capable as any of the experts that will
answer you, but I use Blat.exe to send reports using SMTP. You can download
the exe from www.blat.net and place blat.exe in the same folder as your
application. I use it to email reports that have been converted to pdf.

The following websites are what I used and you may get some ideas from them.

http://www.blat.net/

http://www.blat.net/newdocs/MSAccess_class.html

http://www.freevbcode.com/ShowCode.Asp?ID=109

http://www.rogersaccesslibrary.com/forum/forum_posts.asp?TID=149

There sia lso a blat usergroup on Yahoo groups.

Tony Teows also has a page at: http://www.granite.ab.ca/access/email.htm

Code that I have used is listed below. I use a function written by Francisco
H Tapia and it is in the sample database downloaded from Rogers Access
Library listed above ( if I remember correctly).

The function below is called like this:

SendBlatMail strFromEmail, strFromMail, strToMail, strSubject, strMessage,
strMessageAttachment

Function SendBlatMail(strFromName As String, strFrom As String, strRecipient
As Variant, strSubject As String, strBody As String, Optional
strSavedFileName As Variant)
'-----------------------------------------------------------------------------
----------
' Procedure : SendBlatMail
' DateTime : 2002-12-27 08:27am
' Author : Francisco H Tapia
' Variables : strFromName (email Name), strFrom (email address), strRecipient
(list of address separated by a comma ",")
' strSubject (string), strBody (string), strAttachment (full path
to attachments separated by a comma ",")
' Purpose : Replacement send email function, this function makes a full
call to the BLAT utility.
'-----------------------------------------------------------------------------
----------
'
Dim strRecipientList As String
Dim strAttachmentList As String
Dim strMail As String
Dim i As Integer
Dim strOrganisation As String
Dim strResponse As String
Dim strHost As String

On Error GoTo SendBlatMail_Error
strOrganisation = "Organisation Name"
strHost = "Host name"
If IsArray(strRecipient) Then
For i = LBound(strRecipient) To UBound(strRecipient)
If Len(strRecipientList) = 0 Then
strRecipientList = "-t " & Chr(34) & strRecipient(i)
Else
strRecipientList = strRecipientList & " , " & strRecipient(i)
End If
Next
strRecipientList = strRecipientList & Chr(34)
Else
strRecipientList = "-t " & Chr(34) & strRecipient & Chr(34)
End If
If Not IsMissing(strSavedFileName) And Not IsEmpty(strSavedFileName) Then
If IsArray(strSavedFileName) Then
For i = LBound(strSavedFileName) To UBound(strSavedFileName)
strAttachmentList = " -attach " & Chr(34) & strSavedFileName
(i)
Next
strAttachmentList = strAttachmentList & Chr(34)
Else
strAttachmentList = " -attach " & Chr(34) & strSavedFileName &
Chr(34)
End If
End If
strMail = " " & strAttachmentList
If strMail <> "" Then
strMail = strMail & " -subject " & Chr(34) & strSubject & Chr(34)
Else
strMail = " -subject " & Chr(34) & strSubject & Chr(34)
End If
strMail = strMail & " " & strRecipientList
strMail = strMail & " -f " & Chr(34) & strFrom & Chr(34)
strMail = strMail & " -from " & Chr(34) & strFromName & Chr(34)
strMail = strMail & " -org " & Chr(34) & strOrganisation & Chr(34)
strMail = strMail & " -HostName " & Chr(34) & strHost & Chr(34)
strMail = strMail & " -x " & Chr(34) & "X-INFO: BLAT Message" & Chr(34)
strMail = strMail & " -noh"
strMail = strMail & " -noh2"
strMail = strMail & " -log " & Chr(34) & ShortPath(CurrentProject.path &
"\BlatLOG.txt") & Chr(34)
'ADD YOUR SMTP SERVER IP AND USER ID AND PASSWORD HERE SO THAT THE
MAIL ACTUALLY SENDS.
strMail = strMail & " -server " & Chr(34) & "SMTP SERVER IP" & Chr(34)
strMail = strMail & " -port 25"
strMail = strMail & " -u " & Chr(34) & "SMTP Username" & Chr(34)
strMail = strMail & " -pw " & Chr(34) & "SMTP Password" & Chr(34)
strMail = strMail & " -try 3"
'strMail = strMail & " -debug"
strMail = strMail & " -timestamp"
'Location of BLAT.
Call ShellWait(CurrentProject.path & "\blat.exe" & " - " & strMail & " -
body " & Chr(34) & strBody & Chr(34), vbHide)
i = FreeFile
Open ShortPath(CurrentProject.path & "\BlatLOG.txt") For Input As i
While Not EOF(i)
Input #i, strResponse
If InStr(1, strResponse, "The mail server", vbTextCompare) = 1 Or _
InStr(1, strResponse, "Have you", vbTextCompare) = 1 Then
MsgBox strResponse, vbOKOnly + vbExclamation, "Email Failed!"
End If
Wend
Close #i
Kill ShortPath(CurrentProject.path & "\BLATLOG.txt")

SendBlatMail_Exit:
On Error Resume Next

On Error GoTo 0
DoCmd.Hourglass False
Exit Function

SendBlatMail_Error:
If Err.Number = 2501 Then
Resume Next
Else
Select Case Err
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure SendBlatMail of Module modBlat", vbExclamation + vbOKOnly, "Help."
End Select
End If
Resume SendBlatMail_Exit
Resume

End Function

*********************************

Hope that helps you.
Anthony
 
M

Mark Andrews

I have been using
http://www.ostrosoft.com/smtp_component.asp
you need to click the link for the previous version (their new version
doesn't support vba (I don't think)).
Mainly I picked this one becuase it's cheap and I like the events that show
the email progress/errors.

If you want to use the events for progress/errors you need to register the
dll, otherwise you can just place it in your current directory.

I have also used aspmail in the past (there are dozens of smtp components)

HTH,
Mark
RPT Software
http://www.rptsoftware.com
 
D

Dirk Goldgar

igg via AccessMonster.com said:
i need access 2003 form to send email using smtp protocol. It should get
the
email sendto: addresses from a table of recipients list. any codes,
examples,
etc.?.


When you say you need Access to send e-mail using SMTP, do you really mean
that you need Access to act directly as the SMTP client, and not just use
the user's installed mail client? I ask because you may not be aware of the
built-in SendObject method, that can be used to send e-mail from Access via
the user's MAPI-compliant mail program. That does have the drawback that
the user has to confirm the sending of the message, for security purposes --
though there are a couple of ways to get around that.

I ask because you might not be aware of SendObject, or other ways to send
mail using the installed mail client. If you really need to use SMTP
directly, you can use an SMTP component such as Mark Andrews has suggested.
I'm not familiar with Blat, which biganthony mentioned.
 
I

igg via AccessMonster.com

i know sendobject and was using it. But,it asked for confirmation. i could
not get around that. i use outlook 2003.
 
D

Dirk Goldgar

igg via AccessMonster.com said:
i know sendobject and was using it. But,it asked for confirmation. i could
not get around that. i use outlook 2003.

In addition to SMTP components, you might look into something called Outlook
Redemption.
 
Top