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
Loading
Guest UserPosted May 3, 2011, 7:25 PM
I can't tell what the db.fetchEmail() method is doing, but since you're apparently expecting it to return an email address, then that's where the core of the issue lies.
Sam HobbsPosted May 3, 2011, 6:54 PM
First, note that "mark" is ambiguous. It is both a name of a person such as you and it is the name of something done to a control in a form. So it can be confusing so it took me a few seconds to realize that you were saying Mark to refer to a person, not something the user does in your form.
If you are getting an error, then the first thing to do is to use try/catch blocks and do something to show the error. Also, if you get the error while debugging, then use the debugger to look at details of what is happening. You can also use a breakpoint as John Penn suggests to help see what is happening. There is also something called single-stepping in the debugger that can help.
Mark FenechPosted May 3, 2011, 4:46 PM
Guest UserPosted May 3, 2011, 1:38 PM