Use the SQL Server Stored Procedure sp_send_dbmail to send mail configuration method (text)

Source: Internet
Author: User
Tags mail account

1) create a configuration file and account (create a configuration file and configure database mail Wizard to access the database mail node in the configuration database mail management node and the account Used in the context menu .)

 

Open Database Server ------ manage ------- database mail ------ right-click --- configure database mail (you can also see the configured mail account and configuration file)

The configuration file name is used as a parameter when sp_send_dbmail is used.

Click "add"

Here, the account name can be specified (the description function is enough). The focus is on the configuration of the mail sending server (SMTP): the e-mail address is the sender's mail address, and the display name is the sender's name, reply to the email (which can be the same as the email address). The server name is the port number of the server sending server (smtp.exmail.qq.com For eg: QQ). SMTP authentication: basic Authentication (configure your own mail sender address and password ).

You can add multiple sender accounts. If one account fails, use another account to send messages.

Click "Next"

 

 

 

 

 


2) Configure email
-- You can manually use SQL code to enable the database mail function (if you do not need SQL CODE to enable the database mail function, in the process of configuring the database mail wizard, the system will prompt "whether to enable the database email function". Select "yes)
Exec sp_configure 'show advanced options', 1
Reconfigure
Go
Exec sp_configure 'database mail xps ', 1
Reconfigure
Go
/*
Database Mail retains copies of the sent emails. We can query them through sysmail_allitems, sysmail_sentitems, sysmail_unsentitems, and sysmail_faileditems. The mail sending status will be saved in the sysmail_mailitems table. When the mail is sent successfully, the sent_status column in this table will be displayed as 1; when the mail fails to be sent, the sent_status column will be displayed as 2, and the mail sending status will be 3
As shown below, log files can be viewed in the sysmail_log table
*/


3) send an email.
-- Or execute the stored procedure in the MSDB Database
EXEC sp_send_dbmail @ profile_name = 'db _ mail_test ',
@ Recipients = 'test @ Example.com ',
@ Subject = 'test message ',
@ Body = 'test whether the database email is sent successfully .'

Click "send ......"

Finally, go to the mailbox or view the mail log for verification.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.