Mark Fenech

Mark Fenech

  • NA
  • 82
  • 68.9k

Sending Email C# Problem

May 3 2011 1:25 PM
Hi I am trying to access an email from a table from the Name of the member. Ex: got Mark on Listbox i select and press send i send an email to mark.
This is my Code:
 public DataSet fetchEmail(ListBox list_getEmail)
            {

                string getEmail = list_getEmail.SelectedItem.ToString();
                string query = "SELECT Email FROM tblMember WHERE Member_ID = '" + getEmail + "'";

                ds = new DataSet("MemberDataSet");
                da = new SqlDataAdapter(cmd);
                SqlCommandBuilder sqb = new SqlCommandBuilder(da);
                da.Fill(ds, "tblMember");

                return ds;
            }

Email :

      public void sendMailOutStand()
        {
            MailMessage message = new MailMessage();
            {
                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                smtp.EnableSsl = true;
                smtp.Timeout = 10000;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");

                message.From = new MailAddress("[email protected]", "Mark Fenech");
                string uMail = db.fetchEmail(list_MarchFee).ToString();
                message.To.Add(uMail); // getting exception as not getting good email format
                message.Subject = "Test";
                message.Body = "Test";
                message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                smtp.Send(message);
            }

        }

Thanks

Answers (4)