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

  • SEARCH
  • Home
  • 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 6380109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:13:30+00:00 2026-05-25T02:13:30+00:00

I want to use SQL Server to send email and found two possible way

  • 0

I want to use SQL Server to send email and found two possible way from the internet:

  1. Using AOSMTP.Mail

    Create PROCEDURE [dbo].[RC_SendEmail]  @ServerAddr varchar(80),
       @FromAddr varchar(80), 
       @Recipient varchar(80), 
       @Subject varchar(132),
       @BodyText varchar(2000)
    
    AS
      DECLARE @hr int
      DECLARE @oSmtp int
      DECLARE @nRet int
    
      EXEC @hr = sp_OACreate 'AOSMTP.Mail',@oSmtp OUT
      EXEC @hr = sp_OASetProperty @oSmtp, 'RegisterKey', 'replace this text by your key'
      EXEC @hr = sp_OASetProperty @oSmtp, 'ServerAddr', @ServerAddr
      EXEC @hr = sp_OASetProperty @oSmtp, 'FromAddr', @FromAddr
      EXEC @hr = sp_OAMethod @oSmtp, 'AddRecipient', NULL, @Recipient, @Recipient, 0 
      EXEC @hr = sp_OASetProperty @oSmtp, 'Subject', @Subject 
      EXEC @hr = sp_OASetProperty @oSmtp, 'BodyText', @BodyText 
    
      EXEC @hr = sp_OAMethod @oSmtp, 'SendMail', @nRet OUT 
      EXEC @hr = sp_OADestroy @oSmtp
    

However, this method required a Server Address.

What is the address I am supposed to enter? the email server? or the database server?
I only see that it use ‘localhost’ in the internet. But it doesn’t work for me.

  1. Using CDONTS.NewMail

    CREATE PROCEDURE [dbo].[SendEmail] 
        @From varchar(100),
        @To varchar(100),
        @Subject varchar(100),
        @Body varchar(4000),
        @CC varchar(100) = null,
        @BCC varchar(100) = null
    AS
        Declare @MailID int
        Declare @hr int
        Declare @result int
    
        EXEC @hr = sp_OACreate 'CDONTS.NewMail', @MailID OUT
        EXEC @hr = sp_OASetProperty @MailID, 'From',@From
        EXEC @hr = sp_OASetProperty @MailID, 'Body', @Body
        EXEC @hr = sp_OASetProperty @MailID, 'BCC',@BCC
        EXEC @hr = sp_OASetProperty @MailID, 'CC', @CC
        EXEC @hr = sp_OASetProperty @MailID, 'Subject', @Subject
        EXEC @hr = sp_OASetProperty @MailID, 'To', @To
        EXEC @hr = sp_OAMethod @MailID, 'Send', @result OUT
        EXEC @hr = sp_OADestroy @MailID
        select @result
    

This one required no Server Address but it doesn’t work as well.

Can anyone explain in more details about these and what I should do?

Thank you very much!!!

  • 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-05-25T02:13:30+00:00Added an answer on May 25, 2026 at 2:13 am

    Forget that, use the send email capabilities built-in on SQL Server. It doesn’t get any easier.

    Once you configure it through the wizard, you can simply do this inside your procs, as shown in the tutorial linked:

    USE msdb
    GO
    EXEC sp_send_dbmail @profile_name='PinalProfile',
    @recipients='test@Example.com',
    @subject='Test message',
    @body='This is the body of the test message.'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server and I want to use identity constraint in it I
I want to use ms sql 2005 to send email reminders to my customers.
I'm pulling email address records from a table in SQL Server 2005, and want
I am using ms sql server 2005 and I want to do a mass
Consider this typical disconnected scenario: load a Customer object from SQL Server using LINQ
For my solution I use SQL Server CE. I want to use an ORM
Using emacs on Ubuntu 11.10. I want to connect to a SQL Server database
I want to create a program, that will use SQL Server 2008 database. During
We want to send mail from inside my tomcat web application. I inherited some
Is it possible to use Enterprise Manager 2005 with sqlserver 2005 express? I want

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.