Click here to Skip to main content
15,887,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends, I am trying to the Following code for Sending email from database.

SQL
Step - 1
---------
use master
go
sp_configure 'show advanced options',1
go
reconfigure with override
go
sp_configure 'Database Mail XPs',1
--go
--sp_configure 'SQL Mail XPs',0
go
reconfigure 
go
Step - 2
--------
EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = 'MyMailAccount',
    @description = 'Mail account for Database Mail',
    @email_address = 'makclaire@optonline.net',
    @display_name = 'MyAccount',
 @username='makclaire@optonline.net',
 @password='abc123',
    @mailserver_name = 'mail.optonline.net'

Step-3
-------
EXECUTE msdb.dbo.sysmail_add_profile_sp
       @profile_name = 'MyMailProfile',
       @description = 'Profile used for database mail'
 Step -4
---------
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = 'MyMailProfile',
    @account_name = 'MyMailAccount',
    @sequence_number = 1
Step-5
--------
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'MyMailProfile',
    @principal_name = 'public',
    @is_default = 1 ;

Step-6
-------
declare @body1 varchar(100)
set @body1 = 'Server' +@@servername+  'My First Database Emai'
EXEC msdb.dbo.sp_send_dbmail 
@recipients='myemail@yahoo.com'
    @subject = My Mail Test,
    @body = @body1,
    @body_format = 'HTML'
-------------


after that message is that mail queued.
and i m checking send mail from the following query

SQL
select * from msdb.dbo.sysmail_event_log

but Mail still not send.
I have set SMTP Port Number 25 Enable


Please if u can Solve the above Problem.....
Posted
Updated 5-Jul-10 19:24pm
v2
Comments
TheyCallMeMrJames 5-Jul-10 18:43pm    
on the SQL box, are you able to telnet to port 25 on that mail server? should probably just rule out firewall issues...

1 solution

Try to use below format .

SQL
EXEC msdb.dbo.sp_send_dbmail 
@recipients='User@dmain.com',
@subject = 'Subject Line',
@body = 'Hello',
@body_format='HTML',
@profile_name = 'Profile1',
@file_attachments = 'C:\attachment.txt'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900