Solved

Sending emails via a form in Microsoft Access

Posted on 2004-04-07
22
1,176 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
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

785 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