hi all,
I am working on web application,In web application we are using RDLC reports.
To send an email through report i am giving user credentials static
Instead of giving in .cs page i need to give in .resx file
How should i give the user credentials in .resx file and get them to the .aspx.cs page
please give me the sample code of it :
below is my code:
private void SendMailinxls(ReportViewer reportViewer)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = reportViewer.LocalReport.Render
("Excel", null, out mimeType, out encoding, out extension, out
streamids, out warnings);
MemoryStream memoryStream = new MemoryStream(bytes);
memoryStream.Seek(0, SeekOrigin.Begin);
MailMessage message = new MailMessage();
Attachment attachment = new Attachment(memoryStream, "Report1.xls");
message.Attachments.Add(attachment);
message.From = new MailAddress("aaa@gmail.com");
message.To.Add("bbb@yahoo.com");
message.CC.Add("bbb@yahoo.com");
message.Subject = "Caste Report";
message.IsBodyHtml = true;
message.Body = "Please find Attached Report herewith.";
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
NetworkCredential smtpCredential = new NetworkCredential("aaa@gmail.com", "12345");
smtp.UseDefaultCredentials = true;
smtp.Credentials = smtpCredential;
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Send(message);
memoryStream.Close();
memoryStream.Dispose();
}
web.config file:
<system.net>
<mailSettings>
<smtp from="aaa@gmail.com">
<network host="smtp.gmail.com" port="587" userName="aaa@gmail.com" password="12345" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
I should give the credentials in the resx file in encrypted format instead of giving in web.config and codebehind