How to create profile name for sending mail sqlserver

To create a profile name for sending mail using SQL Server, you'll need to create a SQL Server Agent job that uses a mail profile. Here are the steps:

Step 1: Create a new SQL Server Agent job

  1. Open SQL Server Management Studio (SSMS) and connect to your SQL Server instance.
  2. In the Object Explorer, expand the "SQL Server Agent" node, right-click on "Jobs", and select "New Job...".
  3. In the "New Job" dialog box, enter a name and description for your job, and click "OK".

Step 2: Configure the job to use a mail profile

  1. In the "Job Properties" dialog box, click on the "Steps" tab.
  2. Click on the "New" button to create a new step.
  3. In the "New Job Step" dialog box, enter a name and description for the step, and select "Transact-SQL script (T-SQL)" as the step type.
  4. In the "Command" field, enter the following script:
    EXEC msdb.dbo.sp_send_dbmail @profile_name='Your_Profile_Name', @recipients='[email protected]', @subject='Test Email', @body='This is a test email.'

    Replace Your_Profile_Name with the name you want to give your mail profile, [email protected] with the email address of the recipient, and Test Email and This is a test email. with the subject and body of the email, respectively.

Step 3: Create the mail profile

  1. In the "Job Properties" dialog box, click on the "Advanced" tab.
  2. In the "Advanced" dialog box, click on the "Mail Profile" button.
  3. In the "Mail Profile" dialog box, enter the name and description for your mail profile, and click "OK".

Step 4: Configure the mail profile

  1. In the "Mail Profile" dialog box, click on the "Edit" button.
  2. In the "Edit Mail Profile" dialog box, enter the following information:
    • "From" email address: the email address that will be used as the sender's email address.
    • "To" email address: the email address of the recipient.
    • "Subject" field: the subject of the email.
    • "Body" field: the body of the email.
    • "SMTP Server" field: the name of the SMTP server that will be used to send the email.
    • "Port" field: the port number that will be used to send the email.
  3. Click "OK" to save the changes.

Step 5: Save and schedule the job

  1. Click "OK" to save the job.
  2. In the "Job Properties" dialog box, click on the "Schedules" tab.
  3. Click on the "New" button to create a new schedule.
  4. In the "New Job Schedule" dialog box, enter a name and description for the schedule, and select the frequency and start date for the schedule.
  5. Click "OK" to save the schedule.

That's it! Your SQL Server Agent job should now be configured to send an email using the mail profile you created.