Deepan Raj
Deepan Raj

Reputation: 314

How to Send Mail Without using Password

I want to sent mail without using password of the mailid,Currently i use this code to sent mail.....i hardcode the mail id and pwd

i want to pass the frommail and tomail as parameter, and i dont want a password to send a mail

        System.Net.NetworkCredential cred = new System.Net.NetworkCredential("[email protected]", "demo1234");
        SmtpClient smtp = new SmtpClient("smtp-mail.outlook.com", 587);
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = cred;
        smtp.Send(message);

Please Help Me

Upvotes: 2

Views: 3138

Answers (2)

Isuru
Isuru

Reputation: 450

This is a sample code which you can use. If you have any question please ask!

// Create the Outlook application by using inline initialization.
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.Inspector oInspector = oMsg.GetInspector;

Microsoft.Office.Interop.Outlook.Recipient oTORecipt = oMsg.Recipients.Add(email);
oTORecipt.Type = (int)Microsoft.Office.Interop.Outlook.OlMailRecipientType.olTo;
oTORecipt.Resolve();



oMsg.Subject = "Happy Birthday";
oMsg.HTMLBody = body; //copy the HTML msg body taken from the HTML file. Body is a string

string date = DateTime.Today.ToString("MM-dd-yyyy");
oMsg.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;

oMsg.Save();
oMsg.Display();

 //Explicitly release objects.
 oMsg = null;
 oApp = null; //This has to be done at the end

Remember to add the header file using Microsoft.Office.Interop.Outlook;

Upvotes: 0

Amr Elgarhy
Amr Elgarhy

Reputation: 68902

Ignore setting the credentials and use:

smtp.UseDefaultCredentials = true;

Something like this: https://msdn.microsoft.com/en-us/library/swas0fwc(v=vs.110).aspx#code-snippet-2

Upvotes: 1

Related Questions