Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

I am trying to create a class that will expose send email functionality with input params To,From,Subject and email content.

i want to perform this action with outlook credential that is most of the time windows login.

how can i use outlook credential/windows credential while sending an email.

code snipped i am trying is as follows:

C#
SmtpClient client = new SmtpClient();
         MailMessage msg = new MailMessage();
         System.Net.NetworkCredential smtpCredential = new                                       System.Net.NetworkCredential("tasu007@gmail.com", "");
         client.Host = "smtp.gmail.com";
         client.Port = 587;;
         client.UseDefaultCredentials = false;
         client.Credentials = smtpCredential;
         client.EnableSsl = true;

         MailAddress from = new MailAddress("tasu007@gmail.com");
         MailAddress to =  new MailAddress("tasu007@gmail.com");

         msg.Subject = "test email";
         msg.Body = "Hello Info";
         msg.From = from;
         msg.To.Add(to);
         try
         {
             client.Send(msg);
         }
         catch (Exception ex)
         {
            
         }
Posted

If you want to send mail using Outlook then use the Outlook Interop[^]
 
Share this answer
 
Hi Mark,

i do not want to use outlook to send an email..i just want to use network credential that has been supplied to outlook.

Hope i make it clear this time.

Regards,
Vikas
 
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