Chirag# (11/30/2015)
Hello SSChampionthanks a for your answer , from your query i can get the id but mail was not received in my inbox
also it is not listed in select * from sysmail_allitems
at what position i can show that mailid which is return after execute sp_send_dbmail
all items sent successfully to the service broker would be in sysmail_allitems. If its not, your email is not set up correctly.
have you EVER sent a mail before? maybe you need to start and stop the service? did you send a test email to yourself to prove the service is working?
if you did not get an explicit error in TSQL when you sent it, ie it said "mail queued", then your code is fine, and the issue is downstream and outside of TSQL.
First I'd check if there is an error from the mail server itself in the msdb logs, and look for errors connecting to the server, connection actively refused,or relaying prohibited. i know in my network, i had to make the network admins add my servers explicitly to the white lists by IP address so i could send automated emails.
SELECT top 100
mail.send_request_date As SentDate,
sent_status As Reason,
err.[description],
mail.*
FROM [msdb].[dbo].[sysmail_allitems] mail
inner join [msdb].[dbo].[sysmail_event_log] err
ON err.mailitem_id = mail.mailitem_id
WHERE mail.sent_status <> 'sent'
order by mailitem_id desc
if it's not in the fail mail, then you need to dig deeper into the spam filtering properties of your mail and network;
i'd expect your email was rejected or it is going into a spam filter for whatever you use for mail.
Lowell