c# - 无法从文本框传递变量

标签 c# email smtp gmail

在线

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);
}

最佳答案

代替

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

使用

string subject = "hello" + textBox1.Text;

关于c# - 无法从文本框传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15991831/

相关文章:

c# - Azure 服务总线队列 - 如何防止 IHostedService 立即处理队列消息

android - 在 android 中注册新的 mime 类型

java - 如何从Java中的邮件服务器捕获电子邮件?

c# - SMTP 发送锁定我的文件 - c#

email - 发送电子邮件时 Powershell 超时

c# - 在 Windows Phone 8 模拟器中实现试用时出错

c# - Massive可以和MySql合作吗?

c# - wpf 全局禁用 Tabstop

email - Orgmode latex 导出: #+EMAIL is not exported

PHPmailer gmail 'from' 是gmail帐号