In my console program, I want to send email to someone by using System.Net.Mail.MailMessage
. However, I cannot initialize it :(
namespace:
using System.Net;
using System.Net.Mail;
code:
class emailHelper
{
string to = "jane@address.com";
string from = "ben@address.com";
MailMessage message = new MailMessage(from, to);// errors here
}
the error message is about :
A field initializer cannot reference the non-static field, method, or property 'programA.emailHelper.from'
A field initializer cannot reference the non-static field, method, or property 'programA.emailHelper.to'
I have no idea that do I miss something to set before using MailMessage.
Any idea?