Results 1 to 6 of 6
  1. #1
    fletcjas is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2018
    Location
    Lincoln, UK
    Posts
    23

    Question Send email as HTML template

    Hey,


    I have a question on how to send emails from VBA.

    I have the basic code below to email text, i have added bits into the email body, example would be:

    Hello, **USER**,
    email, email, email......

    Code:
    Set emailObj = CreateObject("CDO.Message")
    emailObj.From = "EMAIL"
    emailObj.To = Me.EmailAddress.Value
    
    
    emailObj.Subject = "Subject"
    emailObj.TextBody = "EMAIL BODY"
    Set emailConfig = emailObj.Configuration
    emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
    'Exclude the following line
    emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = ""
    emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = ""
    emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
    emailConfig.Fields.Update
    
    
    emailObj.Send
    I am looking for / wondering if there is a way of using a HTML template from an external location (website)

    So this would use the HTML template:

    Hello %Users name%,
    Your username is: %Username%
    Your Password: %Password%

    Bla, Bla, Blaa.......
    Location: Website.com/EMAILS/Template.html

    From the code above..

    Is this possible / Any advice. I have looked on the site, but can't see anything.

    Thanks

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Why do you need to strip formatting from a website? If you are sending out an email presumably you have access to the user name/password from the source (SQL table, Access table, etc) You can generate your own format pretty easily without having to parse a website.

  3. #3
    fletcjas is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2018
    Location
    Lincoln, UK
    Posts
    23
    Hey repere,

    At the moment the email is displayed as follows:

    Hello **FIRSTNAME**,

    This is an email to inform you that your account login information has been created.
    This will allow you access to the Portal, accessible via the link below.

    Your username is: **USERNAME**

    Your password is: **PASSWORD**

    Please login and change your password via the portal: https://My.WEBSITE

    If you did not request the request, please contact a member of the team.

    regards

    hello@EMAILADDRESS
    https://WEBISTE
    I am hoping that the website would allow me to edit the template (if needed) without having to update the machines that use the database. Also the text that i would like to send, doesn't fit into the VBA as it is too long and is split across two lines. This causes an error.

    If able, I would like to me able to add a little logo and have it set out well.

    Jase

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    That's not a problem. You can store the template in the database itself, then just replace the fields you want to replace. All you'd need is another table in your database (tblTemplate?) that stores your various email templates then you can just call them up and substitute in your values. I should think this would be a lot easier than parsing a website for information. This is assuming all your users are using a back end table structure so you'd just have to modify the template in one spot.

  5. #5
    fletcjas is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2018
    Location
    Lincoln, UK
    Posts
    23
    The database is split using SQL and a front end '.accdr' file to read it.
    I am able to use a table to store the templates, if needed, but how would i do this, do i need to place the text in the table, as shown below?
    Code:
    emailObj.TextBody = "Hi " & Me.FirstName.Value & "," & Chr(13) & Chr(10) & "" & Chr(13) & Chr(10) & "This is an email to let you know that your account has been created."
    Thanks again.

  6. #6
    fletcjas is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2018
    Location
    Lincoln, UK
    Posts
    23
    I have looked online, and I seem to be able to find a way using outlook, I am hoping to use the same method i have at the moment.
    I can create a table, and store the email templates in there. To be honest, that would be better then using a website and pull the text from there.

    How would i go about doing this? I am happy to learn.

    Thanks

    Jason

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-12-2018, 05:38 AM
  2. Replies: 11
    Last Post: 06-28-2015, 10:46 AM
  3. Replies: 15
    Last Post: 01-07-2015, 02:10 PM
  4. Macro - Output to html using a template
    By thudson in forum Access
    Replies: 1
    Last Post: 04-05-2013, 12:15 AM
  5. Send email using template
    By Kivan in forum Programming
    Replies: 1
    Last Post: 09-07-2012, 12:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums