Receiving Email with SQL Server (SQL 2008R2) - sql

I am trying to get SQL to receive emails, but having some difficulty. Found a blog which starts out with the use of the xp_startmail, but when I try to execute that, I am getting an error. The suggested solution for the error, didn't work...
USE MASTER
GO
SP_CONFIGURE 'show advanced options', 1;
GO
RECONFIGURE;
GO
SP_CONFIGURE 'Database Mail XPs', 1;
GO
RECONFIGURE
GO
EXEC XP_STARTMAIL
GO
Msg 15281, Level 16, State 1, Procedure xp_startmail, Line 1
SQL Server blocked access to procedure 'sys.xp_startmail' of component 'SQL Mail XPs' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'SQL Mail XPs' by using sp_configure. For more information about enabling 'SQL Mail XPs', see "Surface Area Configuration" in SQL Server Books Online.
Any help to get me started would be appreciated....
[EDIT]
**
The only way for SQL Server 2008 to receive email is by using the
legacy stored procedures, such as sp_processmail, with SQL Mail.
Database Mail does not support receiving incoming messages because
there is no IMAP or POP3 support. This may have something to do with
the fact that receiving email can represent a major security risk.
Imagine what a denial-of-service attack on a database cluster could do
to an organization. Or consider the danger of an incoming email
request resulting in the execution of a query such as DROP DATABASE X.
Most SQL Server data is too precious to jeopardize in this manner.
Microsoft has also made it clear that SQL Mail will be phased out in
the next release of SQL Server. Plus, there are many better
alternatives to using this methodology, such as using native Web
services , using .NET CLR-integrated assembly code
**
That's a bit of a nuisance, but makes sense.

Related

Could not find stored procedure "sys.sp_cdc_enable_db_internal"

I'm new to CDC so I started investigating the stored procedures that enable CDC in an SQL Server database. Examining sys.sp_cdc_enable_db and I get the message Could not find stored procedure sys.sp_cdc_enable_db_internal. I've looked all over my database and in the master and msdb databases. Please could anyone tell me why SSMS can't find this stored procedure?
The feature is available only in SQL Server Enterprise and Developer editions, starting with. It can be enabled only using system stored procedures. SQL Server Management Studio provides a wide range of code templates for various feature related actions
To open the templates:
In the SQL Server Management Studio menu, open View
Click Template
Open SQL Server Templates
Open the Change Data Capture sub-folder. The T-SQL templates for administration, configuration, enumeration and meta data querying are available
To set up the feature:
Make sure SQL Server Agent is running. If not, right-click it in Object Explorer and click Start
To enable the feature on the database, open the Enable Database for CDC template in the Configuration sub-folder, and replace the database name with the name of the database you want to track
USE AdventureWorks2012
GO
EXEC sys.sp_cdc_enable_db
GO
The login used must have SQL Server sysadmin privileges and must be a db_owner of the database. Otherwise, you’ll get the following error
sg 22830, Level 16, State 1, Procedure sp_cdc_enable_db_internal, Line
193 The failure occurred when executing the command
‘SetCDCTracked(Value = 1)’. The error returned was 15517: ‘Cannot
execute as the database principal because the principal “dbo” does not
exist, this type of principal cannot be impersonated, or you do not
have permission.’. Use the action and error to determine the cause of
the failure and resubmit the request.
Vist For More Information
https://solutioncenter.apexsql.com/enable-use-sql-server-change-data-capture/

Send email from SQL Server 2005 / 2008

I have to send emails from SQL Server 2005 or 2008. I have done this in the past with additional stored procedures (sp_send_html_mail) and complex configuration / activations. Is there standard build-in stored procedure which sends email via SMTP (not MAPI/CAPI/Outlook profiles)? I found sp_send_dbmail on this topic but not sure is it the only one and what security issues are possible (except spam)?
Yes, sp_send_dbmail is the one to use for both SQL Sever 2005 and 2008.
You will need to make sure it has been configured on your server. It's been a while since I did such a config, but if memory serves me correctly, it is off by default. Have a look at the MS docs for that process, Configure Database Mail. Setting an SMTP server is doable as well. There are lots of options in there so give it a thorough review.
If you are worried about unwanted use of that sp you can use roles and/or execute permission to limit access to it. From the MS docs on troubleshooting dbmail:
To send Database mail, users must be a user in the msdb database and a
member of the DatabaseMailUserRole database role in the msdb database.
To add msdb users or groups to this role use SQL Server Management
Studio or execute the following statement for the user or role that
needs to send Database Mail.
EXEC msdb.dbo.sp_addrolemember #rolename = 'DatabaseMailUserRole'
,#membername = '<user or role name>';
GO

SQL Server 2005: Difference between SQL mail and DB mail

Ok. I know SQL Mail is less secure and old, but what are the real advantages and differences between the two?
I read this article, which is pretty straight forward, but I was hoping to get someone to tell me why (if any) would you want to use SQL mail? Is it really out dated?
Thanks
Benefits of Database Mail over SQL Mail
Database Mail has the option of limiting file sizes to prevent sending large attachments
Database Mail can be configured with multiple SMTP accounts and with multiple profiles
No impact on the database performance, the mailing process is external
Having access to the mail history
Database mail :
Based on SMTP (Simple Mail Transfer Protocol).
Introduced in Sql 2005.
No need to install Outlook.
Depend on Service Broker service.
More secure than Sqlmail.
SQLMail
Based on MAPI (Messaging Application Programming Interface).
Used prior versions of Sql server 2005.
Require Outlook to be installed.
Leass secure than Database mail.
Link :
Database Mail
database-mail-vs-sql-mail

How do you configure a BizTalk WCF-SQL adapter to get data from a SQL Server 2012 "always on" replica database?

We have a client that is going to use the AlwaysOn Availability feature of SQL Server 2012.
They want to have the BizTalk WCF-SQL port connect to the read-only replica.
The documentation on the subject say that the connection has to be made to the SQL Server 2012 Availability Group Listener, and the connection has to be able to set the “ApplicationIntent” parameter. This tells the SQL Listener that the connection is a read-only intent connection, and that it should be redirected to a readable secondary replica. Without that working the connection will be made to the primary database which is not what is wanted.
How do you configure the “ApplicationIntent” parameter on a BizTalk WCF-SQL adapter?
There is no way of doing this via the WCF-SQL adapter.
We have had to go with an external helper class to create the connection with a connection string and query the database.
Update: A Blog written by a colleague on the issue Can I use a BizTalk WCF-SQL send adapter with a SQL 2012 Always on Database? a snippet quoted below.
In summary I think your choices are (in order of preference):
Disable AlwaysOn Availability Groups / Mirroring on SQL server if you need to connect to this SQL server which has this enabled
Disable transactions and implement logic to be able to handle duplicates .
Disable transactions and handle the duplicates or lost messages with custom logic (e.g. Send twice and compare and implement error handling). You need to write your own DTC handling this which is probably very complicated.
Disable transactions and live with risk of duplicates or lost messages without handling duplicates.
I think you'll need to go WCF-Custom + sqlBinding to specify a connection string.
In that link you gave, they did it in the connection string. Look at the last item in it:
Server=tcp:AGListener,1433;Database=AdventureWorks;
IntegratedSecurity=SSPI;ApplicationIntent=ReadOnly
Looks easy enough...

Sending a mail from SQL Server?

is it possible to send an email with SQL Server? I would like to be able to create a procedure for sending an email. It seems that I have to do some configuration according to this site but I don't have admin access on my machine. How can I achieve that ?
Thanks for your help !!
P.S : I am working on Windows
If you have limited privileges on the SQL Server why don't you write the query to obtain the users' names, email adresses and forgotten DVD titles and send the email from you application?
As long as you have access to an SMTP server you should be good to go.
Or you could always try the obvious:
USE YourDB;
GRANT CONTROL SERVER TO ME AS (JON_SKEET OR CHUCK_NORRIS);
GO
:-)
You could use a CLR Stored Procedure.
See this example for instance: Send Email from SQL Server Express Using a CLR Stored Procedure
Sending it via .NET would allow you to relay on a external SMTP and not having to configure Database Mail.
xp_sendmail is the command you want for older versions of SQL Server. Note that this is being removed from future versions, so for versions which support it use Database Mail.
EDIT Sorry - just read your full post. If you don't have the rights to enable mail sending, you'll need to speak to the admin who has. Server security is not designed to be "worked-around". Why does the mail have to be sent from SQL Server?