我想创建一个按钮,当用户点击该按钮时,将打开一个窗口表单,而From是默认文本," To"也是从代码后面加载,用户可以编辑该文本,"内容"是默认文本,用户也可以编辑。
所以现在我可以发送电子邮件:
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
SmtpClient SmtpServer = new SmtpClient("gw1.scei.a-star.edu.sg");
mail.From = new MailAddress("mydefaultemail");
mail.To.Add("the To emails will be input here");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail.";
SmtpServer.Credentials = new System.Net.NetworkCredential("mydefaultemail", "");
SmtpServer.Send(mail);
现在我不知道如何才能将它变为野外形式,并抓住该表格中的文字输入此代码?
答案 0 :(得分:0)
您可以在Windows窗体中添加文本框。
然后,在您的代码中,您将获得该文本框的文本属性值并相应地设置您的电子邮件变量。
mail.Body = myTextBox.Text;
答案 1 :(得分:0)
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(
"yourid@gmail.com", "yourgmailpassword");
MailMessage msg = new MailMessage();
msg.To.Add("Send To email Id");
msg.From = new MailAddress("yourid@gmail.com");
msg.Subject ="Subject";
msg.Body = "Message";
client.Send(msg);