Link to home
Start Free TrialLog in
Avatar of ravon2052
ravon2052

asked on

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
Avatar of Jonathan Kelly
Jonathan Kelly
Flag of Ireland image

do u need to refernce a dll ?
CDONTS maybe ?
Avatar of ravon2052
ravon2052

ASKER

I dont know, i was supplied this code but not sure how to get it working
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 ?
on what line do u get the error ?
.MailFrom = """my company Despatches"" despatches@somewhere.com"

looks a bit suspect, try

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


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
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
i cant, the computer is about 800 miles away.

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

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

i've got the reference thing, from visual editor

What to you think i need to do?
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.



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?


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.


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!
Thanks for that, would you know how to send to mulitpy email adresses?

ASKER CERTIFIED SOLUTION
Avatar of RLGoldberg
RLGoldberg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, is there any other way i can send to two recipents at once?
that is not fair, i am waiting for a response.
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...