1

在线上

const string subject = "hello" + textBox1.Text;

它不打印 textBox1.Text 的值,但我打印单词“textBox1.Text”。我该如何解决?

var fromAddress = new MailAddress("samuimark@gmail.com", "samui mail");
var toAddress = new MailAddress("teeramail@gmail.com", "To Name");
const string fromPassword = "t429";
const string subject = "hello" + textBox1.Text  ;
const string body = "you have a mail";

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}
4

3 回答 3

4

代替

const string subject = "hello" + textBox1.Text  ;

采用

string subject = "hello" + textBox1.Text;
于 2013-04-13T19:21:30.437 回答
0

textBox1.Text 不是常量表达式。将其值赋值给字符串而不是 const 字符串

string subject = "hello" + textBox1.Text;
于 2013-04-14T11:03:56.710 回答
0

安装使用

Subject = subject,
Body = body

我建议你也改变它

Subject = subject.Text,
Body = body.Text

只需将“subject.Text”和“body.Text”更改为您的文本框名称但您必须保留 .Text

于 2013-05-18T18:45:14.990 回答