sending mail
Hi to all,
I was done custom reports using asp.net with sql server 2005. Now i need to send mail custom reports using sql server. Custom reports only i send to client by scheduling basis(daily,weekly or monthly), it will send automatically also.I gone through about sql server agent and database mail but both of these methods working manually , cant attach for custom reports.So i have to send mail custom report using sql server or report manager.
Any one help me....
Thanks & regards,
Sundar
Kirtan PatelPosted Nov 2, 2009, 1:27 PM
Here is Microsoft's Article About "How to Send Mail Using SQL Server " Enjoy :)
http://support.microsoft.com/kb/312839
if my answer helped you then please check "Do you like this answer" :)
sundara moorthyPosted Nov 2, 2009, 1:24 PM
sundara moorthyPosted Nov 2, 2009, 1:22 PM
Posted Nov 2, 2009, 12:39 PM
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace consolemail
{
class Program
{
static void Main(string[] args)
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
System.Net.NetworkCredential AuthInfo = new
System.Net.NetworkCredential("[email protected]", "babilona");
message.To.Add("[email protected]");
message.Subject = "Test Mail using System.Net.Mail";
message.From = new MailAddress("[email protected]");
string str = "Hai to all";
message.Body = str;
bool isBodyHtml = true;
message.IsBodyHtml = isBodyHtml;
message.Attachments.Add(new Attachment("c:\\something.txt"));
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Priority = MailPriority.High;
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = false;
smtp.Credentials = AuthInfo;
smtp.Timeout = 20000;
smtp.Port = 587;
// use stmp.port = 587 if 465 does not work.
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
smtp.Send(message);
Console.WriteLine("E-mail has been sent succesfully");
Console.ReadLine();
}
catch (System.Net.Mail.SmtpException ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
}
Replace with respective gmail id's and attachment as shown in bold....
Finally create a windows service application to run this on a daily basis in the server....
Hope this help...
---------------------------------------------------------------------------------------------------
If my code in someway helped u don't forget to tick it as correct answer..
Sam HobbsPosted Nov 2, 2009, 11:51 AM