Compilation errors to send email with TRIGGER sql - 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

Related

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.

SQL server mail function sp_send_cdontsmail

i wrote a procedure in which i tried to send mail using below command.
EXEC Sp_send_cdontsmail 'from','to','Test','TEST DATA'
After executing its showing "Command(s) completed successfully."
but i am not getting any mail.please help me on this.
You need to configure Database Mail and then use sp_send_dbmail to send mail. This is a supported procedure, part of the SQL Server.
PS. I am aware that out there some code sample circulates that advocates something along the lines of:
CREATE PROCEDURE [dbo].[sp_send_cdontsmail]
...
EXEC #hr = master..sp_OACreate 'CDONTS.NewMail', #MailID OUT
EXEC #hr = master..sp_OASetProperty #MailID, 'From',#From
EXEC #hr = master..sp_OASetProperty #MailID, 'Body', #Body
...
This is horrible code. As one can easily see there is absolutely 0 (zero, nada, zip) error checking in this code. Any failure will be reported as 'success'. COM interop will not raise T-SQL notification messages, is all in the HRESULT, which goes unchecked. Steer away from such code.

dbmail is not working in sql localdb in visual studio

I'm trying to send email with activation link whenever a new user register on my website. but I'm getting activation failure after sending the email from localdb (SQL Server Express)
This is what I've tried
--Enabling Database Mail
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'Database Mail XPs',1
reconfigure
--Creating a Profile
EXECUTE msdb.dbo.sysmail_add_profile_sp
#profile_name = 'Send_Mail',
#description = 'Sending Mail On Register and on some other activity.' ;
-- Create a Mail account for gmail. We have to use our company mail account.
EXECUTE msdb.dbo.sysmail_add_account_sp
#account_name = 'Send_Email_Register',
#email_address = 'abc#gmail.com',
#mailserver_name = 'smtp.gmail.com',
#port=587,
#enable_ssl=1,
#username='abc#gmail.com',
#password='Emailid password'
-- Adding the account to the profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
#profile_name = 'Send_Mail',
#account_name = 'Send_Email_Register',
#sequence_number =1 ;
-- Granting access to the profile to the DatabaseMailUserRole of MSDB
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
#profile_name = 'Send_Mail',
#principal_id = 0,
#is_default = 1 ;
--Sending Test Mail
EXEC msdb.dbo.sp_send_dbmail
#profile_name = 'Send_Mail',
#recipients = 'recipient#gmail.com',
#body = 'Database Mail Testing...',
#subject = 'Databas Mail from SQL Server';
--Verifying, check status column
select * from sysmail_allitems
It looks like DBMail isn't supported on any of the Express instances. The feature breakdown can be seen at http://msdn.microsoft.com/en-us/library/cc645993.aspx#Add_DBServices, and a nice writeup of limitations for the SQL Server 2012 Express edition is in an answer to this thread.

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

sql db mail problem while sending in bulk

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.