从数据库发送邮件 [英] Sending mail from database

查看:206
本文介绍了从数据库发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友您好,我正在尝试以下用于从数据库发送电子邮件的代码.

Hello Friends, I am trying to the Following code for Sending email from database.

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

select * from msdb.dbo.sysmail_event_log


但是邮件仍然无法发送.
我已设置SMTP端口号25启用


请您是否可以解决上述问题.....


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


Please if u can Solve the above Problem.....

推荐答案

尝试使用以下格式.

Try to use below format .

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'


这篇关于从数据库发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆