How to Send Email from Access Using VBA - Table Queue Example

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 26

  • @robinsackmann2828
    @robinsackmann2828 9 місяців тому +1

    Very helpful indeed! Many thanks!

  • @panashechakaodza3418
    @panashechakaodza3418 Рік тому +2

    hello sir how can l create a database that remind me patient review due date automatically in ms acess

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Рік тому

      You could start with a table or query that has your patients, their next review date, and a completed date. Create a query that looks for review dates before today and has a null for completed date. This list will always have the patients that are due but have not been completed yet. Good luck!

  • @DescomplicaAssim
    @DescomplicaAssim 2 роки тому +1

    Thanks for the help!

  • @kyopan23
    @kyopan23 5 місяців тому +1

    Are you sending unencrypted emails with port 25 (2525 in your case) ?
    Is there a way to get this working with an encrypted smtp port sich as 465 or 587?
    Amazing video, you've gained a subscriber! Keep the great work!

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  5 місяців тому

      Awesome, welcome aboard! Yes you can use other ports by switching those during setup, and you can use more secure authentication (though the email will still be unencrypted)

  • @HankMegens
    @HankMegens Рік тому +1

    I have a query that displays all the shifts from an employee for next week. I like to send him/her that report. But as far as I am now, It will sent an email to an employee for every record in the query. So 2 shifts two mails with report, 5 shifts 5 mails. How Do I correct this?

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Рік тому

      Assemble a string for that employee from the query output and then put the string in the message of the report. Loop through the records to build the string, taking the values on each row as you build the list. Here's how you can loop through the records: ua-cam.com/video/7HckYjH_wg4/v-deo.html

  • @shNMIB
    @shNMIB 2 роки тому +1

    Hi sir, how you doing? I was able to run the code, but the email info is kinda duplicating for just one receiver. can please help me.

  • @ibrahimalrabiah1179
    @ibrahimalrabiah1179 2 роки тому +1

    Thank you, but I can’t figure the prblem I follow the code , compiler said sent
    But actually nothing sent or received from email

  • @danviala8816
    @danviala8816 Рік тому +1

    Hi Sean, this worked perfectly until recently when I switched to Microsoft Exchange. I've since had a Transport Error Code 0x800040217, which relates to SMTP authentication. No amount of research has helped, and there's a lot of contradictory online info. Is this an issue you've come across and can you help resolve?

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Рік тому

      Interesting. Some people may get this error for a wrong username and password. Maybe you need to put the full username in or a slightly modified username. I've seen cases where you need to put in username+domain.com instead of @ etc, OR, just the first part of the username without @domain.com etc.

    • @danviala8816
      @danviala8816 Рік тому +1

      @@seanmackenziedataengineering Thank you Sean. It may be a problem with the way I'm using sendmail. I found this on Microsoft " Microsoft 365 or Office 365 does not allow you to send bulk messages via SMTP client submission"

    • @kyopan23
      @kyopan23 5 місяців тому

      ​@@danviala8816were you able to get this working with Exchange? I believe I encountered something similar a while ago. No much information was available but from what I understood had to do with TLS and all that

  • @bumpersmith
    @bumpersmith 2 роки тому +1

    Could you do an example using Gmail?

  • @mustaphati
    @mustaphati 2 роки тому +1

    Can u share with us the file or the code plz

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 роки тому +1

      Sure:
      Sub SendMailFromTable()
      'Send mail from a table
      Dim db As Database
      Dim rst As DAO.Recordset
      Dim strSQL As String
      Dim strFrom As String
      Dim strTo As String
      Dim strCC As String
      Dim strSubject As String
      Dim strBody As String
      Dim lngCounter As Long
      Set db = CurrentDb
      lngCounter = 0
      strSQL = "Select * From EMAIL_TO_SEND Where SentDate Is Null;" 'do not re-send them every time!
      Set rst = db.OpenRecordset(strSQL, dbOpenDynaset) ', dbSeeChanges if on SQL Server linked table
      Do Until rst.EOF
      strFrom = Nz(rst!EmailFrom, "")
      strTo = Nz(rst!EmailTo, "")
      strCC = Nz(rst!EmailCC, "")
      strSubject = Nz(rst!EmailSubject, "")
      strBody = Nz(rst!EmailBody, "")
      lngCounter = lngCounter + 1
      SendMail strFrom, strTo, strCC, strSubject, strBody
      rst.Edit
      rst!SentDate = Now()
      rst.Update
      rst.MoveNext 'VERY IMPORTANT! or never ending loop occurs lol
      Loop
      rst.Close
      Debug.Print lngCounter & " emails sent!"
      Set rst = Nothing
      Set db = Nothing
      'add error handling if needed
      End Sub
      Sub SendMail(strFrom As String, strTo As String, strCC As String, strSubject As String, strBody As String)
      'Send an email!
      Dim objMail
      Dim Url As String
      Url = "schemas.microsoft.com/cdo/configuration/"
      Set objMail = CreateObject("CDO.Message")
      With objMail
      .From = strFrom
      .To = strTo
      .CC = strCC
      .Subject = strSubject
      .HtmlBody = strBody
      End With
      With objMail.Configuration.Fields
      .Item(Url & "sendusing") = 2 'port
      .Item(Url & "smtpserver") = "smtp.myemailserver.com"
      .Item(Url & "smtpserverport") = 2525
      .Item(Url & "smtpauthenticate") = 1 'basic
      .Item(Url & "sendusername") = strFrom
      .Item(Url & "sendpassword") = EMAIL_PASSWORD 'set before, use yours here
      .Update
      End With
      objMail.Send
      Debug.Print "Sent!"
      End Sub

    • @mustaphati
      @mustaphati 2 роки тому

      @@seanmackenziedataengineering thanks a lot

    • @jbbiron2211
      @jbbiron2211 2 роки тому

      @@seanmackenziedataengineering This just gives me a run on error in the " Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)" part, can you help me!

  • @jungjungdelosreyes4147
    @jungjungdelosreyes4147 3 роки тому +1

    dear sir, i like your video it so nice useful. do you share this code? thank you.