Link to home
Start Free TrialLog in
Avatar of johnhinder
johnhinder

asked on

Send Email directly from MS Access Using SMTP

I'm looking at solutions to send HTML-formatted emails via MS Access.

I do not have Outlook reference but do have access to an SMTP server.

Is there a way of doing this? If so, could you you show me the code. I am unable to use any external software or plug-ins/DLLs, just Access and SMTP.
Avatar of Billystyx
Billystyx

The only way I know is the sendobject method, however the below is from the help files, so I don't know if it will help you...

The SendObject action is available only if you have a MAPI-compliant electronic mail application installed on your computer, or if you have a VIM-compliant electronic mail application and have installed and set up Mapivi32.dll.

Billystyx
Avatar of rockiroads
Docmd.SendObject allows you to send formatted HTML mails, just like Billstyx as suggested
It is useful for sending out reports, it basically runs and emails it
You can also use it send text only,


but if you want to send out your own stuff out, the alternative is to use CDO, this allows you to specify your SMTP settings and sends out emails

Avatar of johnhinder

ASKER

Thanks.

Have you got a simple example for using CDO, I've not come across this before.

Thanks,

John
try this, also check the MS website for more info


    Dim objCDOMail As Object
   
   
    'Create a session
    Set objCDOMail = CreateObject("CDO.Message")

    objCDOMail.To = "sendto-emailaaddress"
    objCDOMail.FROM = "sentfrom-emailaddress"
    objCDOMail.CC = "cc-emailaddress"
    objCDOMail.Subject = "subject title"
   
    objCDOMail.TextBody = "message body"
   
    objCDOMail.configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objCDOMail.configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp address e.g. smtp.fred.com"
    objCDOMail.configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    objCDOMail.configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
    objCDOMail.configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
    objCDOMail.configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objCDOMail.configuration.Fields.Update    'Always run update to set your config
   
    objCDOMail.send

    Set objCDOMail = Nothing




the above example doesnt do error checking, its just something to help u understand how to use CDO
I have used this successfully

Excellent. Got it to send a simple email.

However when I tried adding HTML tags to the TextBody they are not displayed in the email when received.

Thanks again.
I cant test it at the moment, not thru the company's  firewall

did u put full html tags in i.e <HTML><HEAD><TITLE></TITLE></HEAD><BODY></BODY></HTML>

not sure if there is a setting for CDO which allows sending of html emails or plain text emails, there might be

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

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
Hello again.

The code in that link works a treat and does everything I want it to.

Thanks for your help,

John
cool, ok and thanks