MailMessage是否需要任何设置来初始化?

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?

查看全部
douji1999
douji1999
2016/11/21 04:27
  • c#
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复