Monday, April 7, 2008

C#- SMTP mail - System.Net.Mail

 

   1: MailMessage message = new MailMessage();
   2: message.From = new MailAddress("sender@foo.bar.com");
   3: message.To.Add(new MailAddress("recipient1@foo.bar.com"));
   4: message.To.Add(new MailAddress("recipient2@foo.bar.com"));
   5: message.To.Add(new MailAddress("recipient3@foo.bar.com"));
   6: message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
   7: message.Subject = "This is my subject";
   8: message.Body = "This is the content";
   9: SmtpClient client = new SmtpClient();
  10: client.Send(message);
  11:  
  12:  

Example of web.config configuration:

   1: <system.net>
   2:     <mailSettings>
   3:       <smtp from="test@foo.com">
   4:         <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
   5:       </smtp>
   6:     </mailSettings>
   7: </system.net>

My example using "localhost":

   1: MailMessage message = new MailMessage();
   2: message.From = new MailAddress("hello@world.com");
   3: message.To.Add(new MailAddress("hello@world.com"));
   4: message.Subject = "Mail from Idea Catcher";
   5: message.Body = "New idea was posted";
   6: SmtpClient client = new SmtpClient("Localhost");
   7: client.UseDefaultCredentials = false;
   8: client.Send(message);

here is the link for iis configuration in case of error - 5.7.1 Unable to relay for xxx - here

source1

source2

Thursday, April 3, 2008

RunAs tweak

If you selected "Select a program from a list of installed programs", you would get this much more useful dialog instead:

image

The registry hack will show you the second Open With dialog instead of that irritating first one.

Manual Registry Hack

Open regedit.exe through the start menu search or run box, and then browse down to the following key (create the key if it doesn't exist)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\

Windows\CurrentVersion\Policies\Explorer

image

Create a new 32-bit DWORD value on the right-hand side with the following values:

  • Name: NoInternetOpenWith
  • Value: 1

The change should be immediate, no need to restart anything. To reset back to default, set the value to 0 or delete the key.

 

Source