I'm not sure if this is exactly the right place to be posting this, but I guess it's worth a shot.
I am working on creating a custom module which needs to send email. I am having issues with the following code, getting an "Object reference not set to an instance of an object" error, which I think means that something isn't instantiated. However, I can't find in here what's not. All the variables in the MailMessage() parameters are set right above the try statement.
If someone could look at this and see what I might be missing, that would be great.
//MailMessage msg = new MailMessage(yourEmail, friendEmail, subject, html);
MailMessage msg = new MailMessage("email@example.com", "firstname.lastname@example.org", "test", "test");
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = mailServer;
smtp.Port = 587;
catch (Exception ex)
lblMessage.Text = ex.InnerException.Message;
lblMessage.Visible = true;