****************************** .Net *********************************************
try
{
string smtpAddress = "smtp.gmail.com";
int portNumber = 587;
bool enableSSL = true;
string emailFrom = "bhavdiptala@gmail.com";
string password = "****";
string emailTo = "bhavdip@dnkmail.in";
string subject = "Hello";
string body = "Hello, I'm just writing this to
say Hi!";
using (MailMessage mail = new MailMessage())
{
mail.From
= new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject
= subject;
mail.Body
= body;
mail.IsBodyHtml
= true;
SmtpClient smtp = new SmtpClient(smtpAddress, portNumber);
smtp.Credentials
= new NetworkCredential(emailFrom, password);
smtp.EnableSsl
= enableSSL;
smtp.Send(mail);
}
}
catch (Exception ex)
{
}
****************************** Sql Server *********************************************
- Go to Object Explorer
- Management
- Right click on Database Mail and select “Configure Database Mail” as follows
- Next
- Select “Setup Database Mail by performing the following tasks” as follows
- Next
- Enter profile name = “SQL Profile” and description as follows
- Click on “Add” button and enter the following details. Always use your own email ID. Generally we have to use here the company email id. We have to raise a ticket to the mail server admin team to get the following details.
- Separate email id for SQL Server (This is From Email ID)
- SMTP server name
- Port number
- SSL feature should be enable or disable.
- OK
- Next
- Under Manage Profile Security option make the profile as public by selecting checkbox and default as follows
- Next
- Accept the default settings for System Parameters as follows
- Next
- Finish
- Close.
USE msdb
GO
EXEC sp_send_dbmail @profile_name='SqlProfile',
@recipients='
bhavdip@dnkmail.in',
@subject='Test message',
@body='This is the body of the test message.'
0 Comments