public User FindUserById(long userId) { User result = null; using (var conn = new SqlConnection("connection_string")) { var sql = @"select PrefersNotification, EmailAddress from dbo.Users where Id = @Id"; using (var cmd = new SqlCommand(sql, conn)) { cmd.Parameters.Add(new SqlParameter("Id", userId)); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { result = new User { Id = userId, PrefersNotifications = (bool)reader["PrefersNotification"], EmailAddress = (string)reader["EmailAddress"] }; break; } } } } return result; }
public void NotifyNewlyRegisteredUser(User user) { var mail = new MailMessage("*****@*****.**", user.EmailAddress); SmtpClient client = new SmtpClient(); client.Port = 25; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = "smtp.google.com"; mail.Subject = "We're glad to have you!"; mail.Body = "Welcome to the site!"; client.Send(mail); }