Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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;
    //SmtpClient client = new SmtpClient("smtp@gmail.com", 587);
    //client.Credentials = smtpCredential;

    //client.Send(email);
    smtp.Send(message);

    memoryStream.Close();
    memoryStream.Dispose();
}

web.config file:
XML
<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
Posted
Updated 19-Apr-15 21:08pm
v2

1 solution

You can use GetLocalResourceObject or GetGlobalResourceObject to read the data from the resource files.
Following link might help:-
https://msdn.microsoft.com/en-us/library/ms227982%28v=vs.140%29.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900