Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:42:38+00:00 2026-06-13T10:42:38+00:00

I am trying to send email from java using SQL Server sp_send_dbmail From within

  • 0

I am trying to send email from java using SQL Server sp_send_dbmail

From within SQL Server itself the following works fine to send an HTML email. [i.e. I have set everything up correctly for sending emails as per
Microsoft’s instructions
]

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'example profile',
    @recipients = 'me@example.com',
    @body = @tableHTML,
    @body_format = 'HTML' ,
    @subject = 'Email from SQL Server';

However when trying to send from java using the following code

public static synchronized int sendEmail(String profileName,String recipients,String body, String body_format,String subject) {
        final String sendEmailStr = "{execute msdb.dbo.sp_send_dbmail (?,?,?,?,?,?)}";
        dbConn  = DBConnection.getInstance();
        Connection conn = dbConn.getConnection();
        CallableStatement stmt = null;
        int result = RESULT_FAILED;
        try {
            stmt = conn.prepareCall(sendEmailStr);
            stmt.setString("profile_name", profileName);
            stmt.setString("recipients", recipients);
            stmt.setString("body", body);
            stmt.setString("body_format", body_format);
            stmt.setString("subject", subject);

            stmt.registerOutParameter(6, java.sql.Types.INTEGER);
            stmt.execute();
            result = stmt.getInt(6);
        } catch(SQLException e) {
            System.out.println(e);
            Log.getInstance().write("Exception on sendEmail " + e.toString());
        } finally {
            try {
                stmt.close();
                dbConn.returnConnection(conn);
            } catch(SQLException e) {
                System.out.println(e);
                Log.getInstance().write("Exception on sendEmail " + e.toString());
            }
        }
        return result;
    }

I get the following exception com.microsoft.sqlserver.jdbc.SQLServerException: com.microsoft.sqlserver.jdbc.SQLServerException: Parameter profile_name was not defined for stored procedure

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:42:39+00:00Added an answer on June 13, 2026 at 10:42 am

    Please change your query string to use call as below:

     final String sendEmailStr "{ call msdb.dbo.sp_send_dbmail (?,?,?,?,?,?) }";
    

    To use the stored proc from your current DB, please execute this in your current DB to wrap the MSDB call through a local procedure:

      Use [MyDatabase]; 
         CREATE PROCEDURE [MyDB].[SEND_EMAIL_DB] 
           @profile_name2 varchar(max), 
           @recipients2 varchar(max), 
           @body2 varchar(max), 
           @body_format2 varchar(max), 
           @subject2 varchar(max), 
           @p_result int OUTPUT 
         AS 
           BEGIN  
              exec msdb.dbo.sp_send_dbmail  @profile_name=@profile_name2,
                       @recipients=@recipients2,@body=@body2,
                       @body_format=@body_format2,@subject=@subject2 
           END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send Email using java mail API from with in a
I'm trying to send email from Clojure using the following code: Helper function that
I am trying to send an email from a Ruby program. The smtp server
I am trying to send email using gmail from my mvc application. I am
I am trying to send email using Exchange 2007 from a console app using
I'm trying to send an email from c# code via our company's exchange server.
I am trying to send an email with an image attachment from Java. I
I am trying to send email using the following method in my action class:
I am trying to send an email from PHP using PHPmailer() . I have
I am not able to send email from my yahoo id using Java mail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.