Send Emails via Sp send db mail

kkran 831 Reputation points
2020-10-23T18:20:04.667+00:00

Hello Everyone - I currently send emails to customers via SQL Procedure
EXEC msdb.dbo.sp_send_dbmail
@Anton _name = @Monique gmx _Profile_Name,
@recipients = @RecipientsList,
--@blind_copy_recipients = @ToddB ,
@Tomas Podoba = @MessageBody,
@subject = @MailSubject,
@Tomas Podoba _Format = 'HTML' ,
@importance ='HIGH',
@from_address = @From,
@Gaydamak _attachments = @Gaydamak _attachment,
@mailitem_id = @mailId OUT;

It's a simple email saying that 'Please log in to portal for viewing the documentation'.
Now the questions can we insert an body of the email into a Image and a link to redirect to portal ?
Sample below :

34539-image.png

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,361 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,601 questions
{count} votes

Accepted answer
  1. MelissaMa-MSFT 24,191 Reputation points
    2020-10-26T05:48:36.987+00:00

    Hi @kkran ,

    As agreed with other experts, your issue is more likely a HTML question.

    You could have a try with below:

    set @MessageBody='  
    <html>  
    <body>  
      
    <p><a href="https://www.***.com">  
    <img src="***.gif" alt="***.com" width="100" height="132">  
    </a></p>  
      
    </body>  
    </html>'  
    

    Or you could post this question on related HTML forum. Thanks.

    Best regards
    Melissa


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

8 additional answers

Sort by: Most helpful
  1. Tom Phillips 17,721 Reputation points
    2020-10-23T19:32:33.667+00:00

    That is really an HTML question, not a SQL Server question. You need to format your @MessageBody in proper HTML format for the picture.

    0 comments No comments

  2. Yitzhak Khabinsky 25,731 Reputation points
    2020-10-23T19:56:04.56+00:00

    Hi @kkran ,

    Check it out my answer on the previous forum here: html-code-inside-sql

    0 comments No comments

  3. Erland Sommarskog 107.1K Reputation points
    2020-10-23T21:42:06.033+00:00

    If you want to insert the message into an image, you will have to work hard. SQL Server is not the venue for manipulating images.

    But you could include an image in the mail by adding an <IMG> that links to an image which is available at some URL.

    As Tom says, this is more an HTML question than an SQL Server question. Or an imaging question, if you want to insert text into images.

    0 comments No comments

  4. Ronen Ariely 15,186 Reputation points
    2020-10-26T06:42:11.107+00:00

    You can also embed image in the email very simple. I have a post about it. All you need is to convert the image to base 64 (another post I have bring a function for this) and then you can imbed the code directly to the image tag in the HTML like this

    34935-image.png

    For example, I send personalize email to user using their images from the database. Each user get email with different image. The image directly read from the database and converted to BASE 64 code

    Most of the design work of the email is as you said HTML/CSS but this part is related to the DBA since the convert needed to be done in the database query level

    0 comments No comments