Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Check if email for each specific recipient was sent or not sql server 2008

Check if email for each specific recipient was sent or not sql server 2008

Scheduled Pinned Locked Moved Database
databasesql-servercomsysadmintutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bjay tiamsic
    wrote on last edited by
    #1

    I have a table with students' details and email address and I send email to them I want to see the logs for each student if it was sent successfully or not. for example:

    STUD_1 student1@email.com failed
    STUD_2 student2@email.com sent

    Can we do it like this? The idea is to get the sent_status from

    sysmail_mailitems

    (or any other accurate/relevant source) for each student.

    W 1 Reply Last reply
    0
    • B bjay tiamsic

      I have a table with students' details and email address and I send email to them I want to see the logs for each student if it was sent successfully or not. for example:

      STUD_1 student1@email.com failed
      STUD_2 student2@email.com sent

      Can we do it like this? The idea is to get the sent_status from

      sysmail_mailitems

      (or any other accurate/relevant source) for each student.

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      If I understand the question correctly, you can use a query like

      SELECT mailitem_id,
      recipients,
      subject,
      sent_status
      FROM sysmail_allitems

      For table description, see sysmail_allitems[^]

      B 1 Reply Last reply
      0
      • W Wendelius

        If I understand the question correctly, you can use a query like

        SELECT mailitem_id,
        recipients,
        subject,
        sent_status
        FROM sysmail_allitems

        For table description, see sysmail_allitems[^]

        B Offline
        B Offline
        bjay tiamsic
        wrote on last edited by
        #3

        can we link sysmail_allitems to my student table? to see if the email was sent or not to a particular student?

        W 1 Reply Last reply
        0
        • B bjay tiamsic

          can we link sysmail_allitems to my student table? to see if the email was sent or not to a particular student?

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          If the students table contains the email address, then you can use that to check if the recipient is equal to student.email. If multiple recipients can be found ind recipients field then you can join using a string search with CHARINDEX function. So either something like:

          SELECT ...
          FROM sysmail_allitems sai,
          student s
          WHERE LOWER(sai.recipients) = LOWER(s.email)

          or

          SELECT ...
          FROM sysmail_allitems sai,
          student s
          WHERE CHARINDEX(LOWER(s.email), LOWER(sai.recipients)) > 0

          Richard DeemingR 1 Reply Last reply
          0
          • W Wendelius

            If the students table contains the email address, then you can use that to check if the recipient is equal to student.email. If multiple recipients can be found ind recipients field then you can join using a string search with CHARINDEX function. So either something like:

            SELECT ...
            FROM sysmail_allitems sai,
            student s
            WHERE LOWER(sai.recipients) = LOWER(s.email)

            or

            SELECT ...
            FROM sysmail_allitems sai,
            student s
            WHERE CHARINDEX(LOWER(s.email), LOWER(sai.recipients)) > 0

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            It's usually cleaner to use the ANSI JOIN syntax, so that you keep the join conditions separate from any filter conditions.

            SELECT
            ...
            FROM
            sysmail_allitems sai
            INNER JOIN student s
            ON sai.recipients = s.email

            Also, most databases don't use a case-sensitive collation, so there shouldn't be any need to use the LOWER function here.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            W 1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              It's usually cleaner to use the ANSI JOIN syntax, so that you keep the join conditions separate from any filter conditions.

              SELECT
              ...
              FROM
              sysmail_allitems sai
              INNER JOIN student s
              ON sai.recipients = s.email

              Also, most databases don't use a case-sensitive collation, so there shouldn't be any need to use the LOWER function here.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              W Offline
              W Offline
              Wendelius
              wrote on last edited by
              #6

              Thanks for the suggestion :)

              Richard Deeming wrote:

              It's usually cleaner to use the ANSI JOIN syntax

              I usually use ANSI join but in this case I felt it would be more understandable to use the 'old' syntax because the variations for the join itself are quite different.

              Richard Deeming wrote:

              most databases don't use a case-sensitive collation, so there shouldn't be any need to use the LOWER function here.

              Not sure about this so I wanted to be on the safe side. I should have written these reasons to the original post in the first place. :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups