从消息框中发送带有字符串的电子邮件 [英] Send email with string from message box

查看:88
本文介绍了从消息框中发送带有字符串的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好-我是编程新手!我正在创建一个程序,允许我自己和我的经理向公司发送电子邮件以请求碳粉.

Hi guys/girls - I'm new to programming! I'm creating a program that allow's myself and my manager to send an email to a company to request toner.

到目前为止,我只有多个复选框,它使我可以选择想要的碳粉,然后单击一个按钮,弹出一个消息,显示我已选择的碳粉.

 So far I just have multiple check box which allows me to select which toner I want then click a button that brings a pop up message showing which toner I have selected. 

现在,这是我感到困难的地方-如何拉出弹出消息框中的字符串并将其插入电子邮件的正文中?

Now here's what I find difficult - How do I pull the string that is in the pop up message box and insert it into the body of my email? 

这是我的按钮代码- 

Here is my code for the button - 

 MailMessage mm = new MailMessage("REPLY TO ADDRESS HERE", "RECIPIENT'S ADDRESS HERE", "EMAIL SUBJECT HERE", "EMAIL BODY HERE, THIS IS WHERE I WANT THE STRING TO BE INPUTTED AUTOMATICALLY DEPENDING ON WHICH TONER I HAVE SELECTED ");
            mm.BodyEncoding = UTF8Encoding.UTF8;
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

            client.Send(mm);

            List<string> checkedItems = (from Control c in Controls where c is CheckBox && ((CheckBox)c).Checked select c.Text).ToList();
            MessageBox.Show(string.Join(", ", checkedItems));

           
        }



推荐答案

您好Shivvv96,

Hi Shivvv96,

以下是根据您的描述提供的示例,希望我的回复对您有所帮助.

Here is a sample based on your description, hopping my reply is helpful for you.

List<string> checkedItems = (from Control c in Controls where c is CheckBox && ((CheckBox)c).Checked select c.Text).ToList();
string mailBody = string.Join(", ", checkedItems);

MailMessage mm = new MailMessage("from_email@xx.com", "to_email@xx.co");
mm.Subject = "Put your email subject here";
mm.Body = mailBody;
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

SmtpClient client = new SmtpClient();
//you also need to set send mail configuraiton before sending the mail 
//for example, mail host and credentials
client.Send(mm);

最好的问候,
王丽

Best Regards,
Li Wang


这篇关于从消息框中发送带有字符串的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆