Archive for October 2009
Sending an email from C# winforms application is exactly same as we do in webapps using System.Net.Mail namespace. Here is a sample code which sends out an email with an attachment (again it is not specific to winforms can be used in webapps as it is).
MailMessage msg = new MailMessage(); if (varEmailID.IndexOf(',') > 0) msg.Attachments.Add(attach); string FromEmail = ConfigurationSettings.AppSettings["SystemMailID"]; msg.From = new MailAddress(FromEmail); client.Send(msg);
Attachment attach = new Attachment(filepath);
iDs = varEmailID.Split(',');
for (int i = 0; i <= iDs.Length - 1; i++)
msg.Subject = varSubject;
msg.Body = varBody;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.Normal;
string SmtpServer = ConfigurationSettings.AppSettings["SmtpServer"];
string UserName = ConfigurationSettings.AppSettings["UserName"];
string Password = ConfigurationSettings.AppSettings["Password"];
client = new SmtpClient(SmtpServer);
client.UseDefaultCredentials = false;
System.Net.NetworkCredential creds = new System.Net.NetworkCredential(UserName, Password);
client.Credentials = creds;
MailMessage msg = new MailMessage();
if (varEmailID.IndexOf(',') > 0)
string FromEmail = ConfigurationSettings.AppSettings["SystemMailID"];
msg.From = new MailAddress(FromEmail);
Having more than 150 tables and even more SPs in a database and then using LinqToSql for that is proving to be a bottleneck.
LinqToSql is an awesome technology but working in a team of more than 5 developers, all trying to update a single dbml at the same time is not a good idea. You won’t notice this while working on a team of 1 or 2 developers , I still think subsonic or NHibernate would have been a better solution at least for the reason being they generate separate class files for each entity.
Asp.Net 4 (aka Framework 4.0 ) with VS 2010 now supports URL routing for webforms.
It would be a cool thing since Asp.net MVC was already supporting it out of box and this is just a sign that webforms are going to be a supported as prime platform for developments by MS.
Check here for more details.
Found an interesting piece of code here.
When sending an email in your ASP.NET application there are times when you do not want the user experience to slow just to wait for an email to be sent. The code sample below is how to send a System.Net.Mail.MailMessage asynchronously so that the current thread can continue while a secondary thread sends the email.
public static void SendEmail(System.Net.Mail.MailMessage m)
public static void SendEmail(System.Net.Mail.MailMessage m, Boolean Async)
System.Net.Mail.SmtpClient smtpClient = null;
smtpClient = new System.Net.Mail.SmtpClient("localhost");
SendEmailDelegate sd = new SendEmailDelegate(smtpClient.Send);
AsyncCallback cb = new AsyncCallback(SendEmailResponse);
sd.BeginInvoke(m, cb, sd);
private delegate void SendEmailDelegate(System.Net.Mail.MailMessage m);
private static void SendEmailResponse(IAsyncResult ar)
SendEmailDelegate sd = (SendEmailDelegate)(ar.AsyncState);
To use this just call the SendEmail() method with System.Net.Mail.MailMessage object.