在TO和CC字段中放置多个字段 [英] putting multiple fields in TO and CC fields

查看:86
本文介绍了在TO和CC字段中放置多个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写代码从我的应用程序向用户发送电子邮件,我把TO,CC和主题文本框中提到了Recepients但问题是我只能在To和CC字段中提到1个接收者,我只是想知道如何添加多个reciepient,就像在Outlook中我们提到多个接收器,如冒号,例如



user1@yahoo.com; user2@hotmail.com; user3@gmail.com; ........................



与CC相同



i有一个简单的文本框TO我可以在其中放置1个地址



怎么做?



代码:



i wrote code to send emails to user from my application , i put TO, CC and Subject textboxes in which i mention Recepients but problem is that i can only mention 1 recepient in To and CC fields, i am just wondering that how to add multiple reciepient, like in Outlook we mention multiple recepients like with colon e.g.

user1@yahoo.com; user2@hotmail.com; user3@gmail.com; ........................

same in CC

i have a simple text box TO in which i can put 1 address

how to do that ?

CODE:

<pre lang="c#">using System.Net.Mail;
using System.Net;
using Outlook = Microsoft.Office.Interop.Outlook;

public ActionResult dailyLog(String txtEmailTo, String txtCC, String txtSubject, String txtBody) 
        {
            if (!String.IsNullOrEmpty(Session["Admin"] as string))
            {
                try
                {
                    Outlook.Application oApp = new Outlook.Application();
                    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                    oMsg.HTMLBody = txtBody;
                    //Add an attachment.
                    //String sDisplayName = "MyAttachment";
                    int iPosition = (int)oMsg.Body.Length + 1;
                    //int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                    //now attached the file
                    //Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);
                    //Subject line
                    oMsg.Subject = txtSubject;
                    // Add a recipient.
                    Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(txtEmailTo);
                    oRecip = oRecips.Add(txtCC);
                    oRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
                    oRecip.Resolve();
                    // Send.
                    oMsg.Send();
                    // Clean up.
                    oRecip = null;
                    oRecips = null;
                    oMsg = null;
                    oApp = null;
                    ViewBag.Confirmation = "Daily Has Been Log Submitted";
                    return View();
                }
                catch (Exception ex)
                {
                    ViewBag.Confirmation = ex.Message;
                    return View();
                }
            }

推荐答案

在TO和CC字段中输入多个电子邮件地址时指示您的用户分开用逗号或分号表示。
Instruct your users when entering multiple email address in the TO and CC fields to separate them with either a comma or semicolon.


这篇关于在TO和CC字段中放置多个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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