Sending emails via a form in Microsoft Access

Hi,
How do i go about sending an email from the contents of a form. I have this code below but the CreateObject("OSSMTP.SMTPSession") doesn't work as it comes up a runtime error 429.



'Start of the email code

Set oSMTPSession = CreateObject("OSSMTP.SMTPSession")

With oSMTPSession
 ' EndEmail = "For Parcelforce deliveries, you can also track the parcel on {web address removed - ee_ai_construct, CS Moderator} using the consignment number TP7214102. Or alternatively you may telephone them on {telephone number removed - ee_ai_construct, CS Moderator}." & vbCrLf & vbRcLf & "Please ensure someone is at this address to receive the parcel. If no-one is present, a card will be left so you can contact Parcel Force to arrange re-delivery or collection. Note that normal delivery is between 9am and 6pm. We can't make tracing enquiries until the day after the delivery date. This order cannot now be cancelled." & vbCrLf & vbRcLf & "If the goods are faulty, please contact sales@somewhere.com for returns information." & vbCrLf & vbCrLf & vbRcLf & "Thank you very much for your business we hope to be able to help you again soon..." & vbCrLf & vbCrLf & vbRcLf & "My company" & vbCrLf & "Units 1 and 2," & vbCrLf & "Street Way," & vbCrLf & "Camley Street," & vbCrLf & "Soctland," & vbCrLf & "N19 0PD" & vbCrLf & vbCrLf & "Tel : 020 1111 1111" & vbCrLf & "Fax : 020 1111 1114"
 ' MiddleMail = "abroad for as little as £2.00 (much less than most other companies charge) unfortunately this is an untracked service and may take up to 2 weeks to arrive." & vbCrLf & vbCrLf & vbRcLf & "Please keep this Email until the parcel arrives." & vbCrLf & vbCrLf & vbRcLf & "Courier : " + Emethod & vbCrLf & "Tracking Number : " + Etracknum & vbCrLf & vbCrLf & vbRcLf
  .MailFrom = """my company Despatches"" despatches@somewhere.com"
  .SendTo = Erecipient
  .Server = "send.mail.uk.vianw.net"
  .Port = 25
  .MessageSubject = "Order number " + Eordernum + " despatched. PLEASE DO NOT REPLY !"
  .MessageText = BeginningMail + MiddleMail + EndMail
  'authenticate if your mail server require it
  '.AuthenticationType = 1 'POP3 authentication
  '.POPServer = "mailserver.mydomain.com"
  '.Username = "test"
  '.Password = "test"
 
  'if SMTP Component incorrectly detects message date/time, you can over-write it using TimeStamp property
  .TimeStamp = Format$(Date, "d mmm yyyy") + " " + Format$(Time, "hh:mm:ss")
 
 
  'SMTP Component defaults to "US-ASCII" character set, to change it use Charset property
  '.Charset = "GB2312"
 
  'adding attachments
  'using Attachment object
  'Set oAttachment = CreateObject("OSSMTP.Attachment")
  'oAttachment.FilePath = "D:\temp\sample.txt"
  'oAttachment.AttachmentName = "test file"
  'oAttachment.ContentType = "application/xml"
  'oAttachment.ContentTransferEncoding = 1 'enc7Bit
  '.Attachments.Add oAttachment
  'by attachment location. In this case attachment_name = {file name}, content_type will be
  'autodetected (based on your Registry settings), content_transfer_encoding = {64 bit}
  '.Attachments.Add "D:\temp\test.exe"
 
  'adding custom headers
  'using CustomHeader object
  Set oCustomHeader = CreateObject("OSSMTP.CustomHeader")
  oCustomHeader.HeaderName = "Return-Path"
  oCustomHeader.HeaderValue = "postmaster@mydomain.com"
  .CustomHeaders.Add oCustomHeader
  'in a single string
  .CustomHeaders.Add "Reply-To: errors@mydomain.com"
 
  .SendEmail
End With

Set oSMTPSession = Nothing

Any help is much appreciated
ravon2052Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
RLGoldbergConnect With a Mentor Commented:
I believe that, based on the code, you will need to execute the code once per e-mail.  You might get creative and do a call-in-a-call but you will still need it to go through each time for each address.
0
 
Jonathan KellyCommented:
do u need to refernce a dll ?
CDONTS maybe ?
0
 
ravon2052Author Commented:
I dont know, i was supplied this code but not sure how to get it working
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
Jonathan KellyCommented:
ive never used code like yours above but

Set oSMTPSession = CreateObject("OSSMTP.SMTPSession")

would suggest that you need to reference a dll in oder to use OSSMTP

only guessing here.

does the code compile cleanly ?
0
 
Jonathan KellyCommented:
on what line do u get the error ?
0
 
Jonathan KellyCommented:
.MailFrom = """my company Despatches"" despatches@somewhere.com"

looks a bit suspect, try

.MailFrom = "my company Despatches despatches@somewhere.com"


0
 
ravon2052Author Commented:
i get the error on line

Set oSMTPSession = CreateObject("OSSMTP.SMTPSession")


i think i do need a dll. how do i go about it


the person that sent me the code, i have seen it working on his comp
0
 
Jonathan KellyCommented:
I would suggest having a look at the comp where the code runs ok and look at the refences - Tools\Refernces

There may be a reference listed there which you are missing
0
 
ravon2052Author Commented:
i cant, the computer is about 800 miles away.

there is no Tools | references opition in my menu, using access 2003
0
 
Jonathan KellyCommented:
can u give them a call

youll find References by opening a module and going
to Tools | References
0
 
ravon2052Author Commented:
unforuntaley no, no number

i've got the reference thing, from visual editor

What to you think i need to do?
0
 
Jonathan KellyCommented:
can you contact the other site somehow - email ?

get them to send u a list of the references used by the app ?

or get them to send u a copy of the app - when u open their copy on your machine you should  see that there is a MISSING reference and thats the culprit.



0
 
ravon2052Author Commented:
i have the whole database here, when i open it, it asks me to enable macros, i click yes. there is no missing refernece

the person who gave me the file doesn't know much about access. what all do i need to ask him?
0
 
Jonathan KellyCommented:


you have checked under Tools | References and nothing is listed as missing  and you can compile cleanly ?

If can get someone to
open the app
bring up the db container
open a module
goto Tools | References
list the selected references.


0
 
RLGoldbergCommented:
I have seen this code before.  It is put out as freeware by OstroSoft and you can get more information here...
http://www.ostrosoft.com/smtp_component.asp

You need to download the file and then register it in your system for it to work.

Good Luck!
0
 
ravon2052Author Commented:
Thanks for that, would you know how to send to mulitpy email adresses?

0
 
ravon2052Author Commented:
Hi, is there any other way i can send to two recipents at once?
0
 
ravon2052Author Commented:
that is not fair, i am waiting for a response.
0
 
RLGoldbergCommented:
Ravon:

According to the web site for Ostro Soft, see link above, it says:
* You can specify multiple recipients in SendTo, CC and BCC fields, using comma-separated list:
<addr2@yourhost.com>, addr1@yourhost.com,"recipient name" <addr3@yourhost.com>

Hope this helps.

dataDOC
Code On...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.