sql db mail problem while sending in bulk - sql

I am using db mail(sql server 2005) to send bulk email(>2000).
The code tat i use is,
exec msdb..sp_send_dbmail
#profile_name = 'My Profile',
#recipients = 'raghav.cinch#gmail.com',
#subject = 'test',
#body = 'test',
#body_format = 'HTML'
If i send few emails(less than 100), all emails are sent successfully. But only bulk emails give me error.
The error I get is,
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 8 (2011-09-27T21:29:17). Exception Message: Cannot send mails to mail server. (Unable to send to all recipients.).
)
The error comes after 100 or 105 mails. The email addresses are correct and if i sent in cycles of 100, all mails are sent successfully.
I believe it should be some configuration settings tat need to be tweaked. Could someone pls help me in fixing it..
Thanks in advance.

Changed the iis6 settings, max queue length for the smtp server and this worked like charm.

Related

SQL Server job error on email notification

I have configured a database email, operators, and such on my SQL managed instance, to receive an email when a job fails.
In the email, we get something like this "The yyy_job failed on step 3".
But my question is... Is there a way to add the error message on the body of the email? I've been searching for this, but can't fine a suitable answer.
Thank you in advance
As far as I know there's no way to add further details to the email notifications when a job fails.
The only way is to implement your own notification process.
https://www.sqlshack.com/reporting-and-alerting-on-job-failure-in-sql-server/
We have a similar set up. We have a SQL Server Agent job that consists of several steps.
I configured it in such a way that we receive notification email when the job starts and another email when it finishes. There are two versions of the final email - one for success, another for failure.
At the end of the job there are two final steps called "Email OK" and "Email FAIL". Note how each of the steps have their "On Success" and "On Failure" configured.
This is how "Email OK" and "Email FAIL" steps look like in our case:
In my case I simply have different subjects of the emails, so it is easy to filter in the email client.
You can write any extra T-SQL code to execute a query against msdb.dbo.sysjobhistory and include the relevant result into the email.
I will not write a complete query here, but I imagine it would look similar to my sketch below. If you need help with that, ask another question.
This is how you can use msdb.dbo.sp_send_dbmail to include the result of some query into the email text:
EXEC msdb.dbo.sp_send_dbmail
#profile_name = 'ABC'
,#recipients = 'abc#example.com'
,#subject = 'Some subject line'
,#body = #VarBody
,#body_format = 'TEXT'
,#importance = 'NORMAL'
,#sensitivity = 'NORMAL'
,#query = N'
-- show latest entry in the log for your job
SELECT TOP(1)
message, ...
FROM
msdb.dbo.sysjobhistory
WHERE
job_id = ''your job ID''
ORDER BY
instance_id DESC;
'
,#execute_query_database = 'msdb'
;
Have a look at the documentation for a list of parameters for sp_send_dbmail. Example above inlines the query result. You can also attach it as a separate file.

How to send message through sql with an image

In my SQL, I already created profile & account.
I also know how to send the message though code :
USE msdb
GO
EXEC sp_send_dbmail #profile_name='yourprofilename',
#recipients='test#Example.com',
#subject='Test message',
#body='This is the body of the test message.
Congrates Database Mail Received By you Successfully.'
** Above is an example
However, I was wondering how can I insert an image into the message.

Compilation errors to send email with TRIGGER sql

Hello i'm working on PL/SQL Developper and i've got an annoying error ... I'm trying to make a trigger to send an email when something is added in the "JDEF" database.
This is my code :
CREATE OR REPLACE TRIGGER Send_Email
AFTER INSERT
ON JDEF
BEGIN
EXEC msdb.dbo.sp_send_dbmail
#profile_name = 'me',
#recipients = 'example#ent.com',
#body = 'The stored procedure finished successfully.',
#subject = 'Automated Success Message'
END
The error compilation are for those two lines : EXEC msdb.dbo.sp_send_dbmail AND #profile_name = 'me'. They speak about "MSDB" and ",' symbols who are replaced by other one to compile.
Have you any ideas to help me ?
thx
Your code looks like mssql in oracle standard way to send email is for example:
UTL_MAIL.send(sender => 'me#ent.com',
recipients => 'example#ent.com',
subject => 'Automated Success Message',
message => 'The stored procedure finished successfully.',
mime_type => 'text; charset=us-ascii');
But it needs being enabled before you can use UTL_MAIL. Another package to send mail is UTL_TCP
This may be helpful: http://www.orafaq.com/wiki/Send_mail_from_PL/SQL

Database Mail not sending

I'm trying to send email using the DatabaseMail on SQL Server 2008; I can see my emails sitting in the msdb.dbo.sysmail_unsentitems
But they just sit there and I get no error messages.
I've checked and I have rights to use the DatabaseMail by using the following:
EXEC msdb.sys.sp_helprolemember 'DatabaseMailUserRole';
And I tried running
EXEC msdb.dbo.sysmail_help_queue_sp #queue_type = 'mail';
which shows the length as the number of emails I've tried to send, but the Status is showing as Inactive.
Am I missing something else?

sp_send_dbmail with Binary Attachment Issue

I am attempting to use sp_send_dbmail to send out an attachment.
The attachment is stored in a varbinary(MAX) column in a table. Here is my query:
EXEC msdb.dbo.sp_send_dbmail
#recipients='mick.walker#somewhere.com',
#subject = 'Test Attachment',
#body = 'Test',
#body_format = 'HTML',
#profile_name = 'intranetadmin',
#query = 'Select DocumentData from [myDB].[dbo].[Documents] Where DocumentID = 8',
#query_result_header = 0,
#attach_query_result_as_file = 1,
#query_attachment_filename = 'Test.pdf',
#exclude_query_output = 1,
#query_no_truncate = 0;
The email sends sucessfully with a pdf attachment. However when it comes to opening the attachment, I get an error. I think the size of the file is being truncated, even though I explicitaally state no to in my query.
I have checked the MAX allowed message size in the Database Mail settings and it is currently 104857600 bytes (100mb), the files I am attempting to send, are nowhere near this size - so I am a little puzzled.
I know this is an old thread but I have just come across the same issue. The problem is SQL reported an error and has stored the error message in the attachment.
Change the name of the attachment to have a .txt extension and send the email. Open the .txt file and view the error. It is probably something to so with a security configuration.
Try setting #query_no_truncate parameter to 1. When large variable length data types are used in the query and this option is 0 or not specified data gets cut to 256 characters. Reference: http://msdn.microsoft.com/en-us/library/ms190307.aspx