locked
Send E-Mail RRS feed

  • Question

  • Hi All ,

    1. We have mysql Database that has 2 tables user and and time entries .

    2.Connected to the mysql Database via linked server

    3. I have written a query to find the ids,names & their email addresses of the users who have not filled there time sheets .

    Requirement is :

    4. Send the email on individual basis to the users whose name is in the query .

    Kindly Suggest

    Priya
    Friday, November 22, 2013 12:24 PM

Answers

  • You can use sp_send_dbmail for that

    see

    http://technet.microsoft.com/en-us/library/ms190307.aspx

    you would need a logic to get emails in a dlimited format as below

    DECLARE @EMailList varchar(max)
    SET @EmailList=STUFF((SELECT ';' + Email 
    FROM Linkedservername.dbname.dbo.tablename
    ....any conditions here
    ),1,1,'')
    
    

    Then pass @EMailList to parameter

    @recipients 

    of sp_send_dbmail procedure.

    I hope subject of the mail would be static otherwise you need a loop to create subject for each user and then sent the mail.


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs


    • Edited by Visakh16MVP Friday, November 22, 2013 12:36 PM
    • Marked as answer by Priya Bange Friday, November 22, 2013 2:11 PM
    Friday, November 22, 2013 12:35 PM

All replies

  • If SQL Server edition is Express visit this link:

    Send Email from SQL Server Express Using a CLR Stored Procedure

    otherwise see this page please:

    sp_send_dbmail (Transact-SQL)


    sqldevelop.wordpress.com

    Friday, November 22, 2013 12:33 PM
  • You can use sp_send_dbmail for that

    see

    http://technet.microsoft.com/en-us/library/ms190307.aspx

    you would need a logic to get emails in a dlimited format as below

    DECLARE @EMailList varchar(max)
    SET @EmailList=STUFF((SELECT ';' + Email 
    FROM Linkedservername.dbname.dbo.tablename
    ....any conditions here
    ),1,1,'')
    
    

    Then pass @EMailList to parameter

    @recipients 

    of sp_send_dbmail procedure.

    I hope subject of the mail would be static otherwise you need a loop to create subject for each user and then sent the mail.


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs


    • Edited by Visakh16MVP Friday, November 22, 2013 12:36 PM
    • Marked as answer by Priya Bange Friday, November 22, 2013 2:11 PM
    Friday, November 22, 2013 12:35 PM