Solved

Sending emails via a form in Microsoft Access

Posted on 2004-04-07
22
1,183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
  • 3
22 Comments
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 10773820
do u need to refernce a dll ?
CDONTS maybe ?
0
 

Author Comment

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

Expert Comment

by:Jonathan Kelly
ID: 10774264
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 7

Expert Comment

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

Expert Comment

by:Jonathan Kelly
ID: 10774291
.MailFrom = """my company Despatches"" despatches@somewhere.com"

looks a bit suspect, try

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


0
 

Author Comment

by:ravon2052
ID: 10774311
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
ID: 10774427
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
ID: 10774513
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
ID: 10774571
can u give them a call

youll find References by opening a module and going
to Tools | References
0
 

Author Comment

by:ravon2052
ID: 10774612
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
ID: 10774699
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
ID: 10774760
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
ID: 10774867


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

0
 
LVL 3

Accepted Solution

by:
RLGoldberg earned 125 total points
ID: 10801031
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
ID: 11143938
Hi, is there any other way i can send to two recipents at once?
0
 

Author Comment

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

Expert Comment

by:RLGoldberg
ID: 11182812
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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