I am trying to setup email in a webapp I am working on. Here is the code I have so far:
public void SendReminderEmail(System.Web.HttpContext context, string emailSubject, string emailTo, string emailFrom, string emailBody, string SMTPServer)
{
System.Net.Mail.MailAddress mailTo = new System.Net.Mail.MailAddress(emailTo);
System.Net.Mail.MailAddress mailFrom = new System.Net.Mail.MailAddress(emailFrom);
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(mailFrom, mailTo);
message.IsBodyHtml = true;
message.Subject = emailSubject;
message.Body = emailBody;
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(SMTPServer);
smtpClient.Send(message);
}
protected void SendEmail_Click(object sender, EventArgs e)
{
string emailSubject = "Test Subject";
string emailTo = "Will put an email address in here.";
string emailFrom = "Will put an email address in here";
string emailBody = "Test Email";
string SMTPServer = "Will put an smtp server in here;
this.SendReminderEmail(this.Context, emailSubject, emailTo, emailFrom, emailBody, SMTPServer);
}
So when the adminstrator clicks the button, it is going to fire off an email to a group of people. The problem I have is that I am getting this error:
"Mailbox name not allowed. The server response was: Sorry, that domain isn't in my list of allowed rcpthosts."
And it points to the line, smtpClient.send(message)
When I run it, I actually have email addresses and an smtpOut server in there. I just didn't include them in here for security sake. Anyone have an idea what is causing that error?
Thanks.
Answers
Know the answer? Post it. Somebody with the same question will find it here.