Solved

Sending emails via a form in Microsoft Access

Posted on 2004-04-07
22
1,173 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:ravon2052
  • 8
  • 8
  • 3
22 Comments
 
LVL 7

Expert Comment

by:Jonathan Kelly
Comment Utility
do u need to refernce a dll ?
CDONTS maybe ?
0
 

Author Comment

by:ravon2052
Comment Utility
I dont know, i was supplied this code but not sure how to get it working
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
Comment Utility
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
 
LVL 7

Expert Comment

by:Jonathan Kelly
Comment Utility
on what line do u get the error ?
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
Comment Utility
.MailFrom = """my company Despatches"" despatches@somewhere.com"

looks a bit suspect, try

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


0
 

Author Comment

by:ravon2052
Comment Utility
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
 
LVL 7

Expert Comment

by:Jonathan Kelly
Comment Utility
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
 

Author Comment

by:ravon2052
Comment Utility
i cant, the computer is about 800 miles away.

there is no Tools | references opition in my menu, using access 2003
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
Comment Utility
can u give them a call

youll find References by opening a module and going
to Tools | References
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:ravon2052
Comment Utility
unforuntaley no, no number

i've got the reference thing, from visual editor

What to you think i need to do?
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
Comment Utility
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
 

Author Comment

by:ravon2052
Comment Utility
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
 
LVL 7

Expert Comment

by:Jonathan Kelly
Comment Utility


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
 
LVL 3

Expert Comment

by:RLGoldberg
Comment Utility
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
 

Author Comment

by:ravon2052
Comment Utility
Thanks for that, would you know how to send to mulitpy email adresses?

0
 
LVL 3

Accepted Solution

by:
RLGoldberg earned 125 total points
Comment Utility
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
 

Author Comment

by:ravon2052
Comment Utility
Hi, is there any other way i can send to two recipents at once?
0
 

Author Comment

by:ravon2052
Comment Utility
that is not fair, i am waiting for a response.
0
 
LVL 3

Expert Comment

by:RLGoldberg
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now