如何使用分号接收电子邮件 [英] how to send email in recepient with semicolon

查看:128
本文介绍了如何使用分号接收电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我发送电子邮件的代码

我想寄一个收件人,就像

abc@yahoo.com; cdef@gmail.com; jdfdf@yahoo.com
abc @ yahoo.com,bcd @ yahoo.com


就像在收件人中,我想使用分号或逗号,但都希望在编码中接受..如何做到这一点的任何想法?

Hi this is my coding for sending an email

I want to send a recepient as like

abc@yahoo.com;cdef@gmail.com;jdfdf@yahoo.com
abc@yahoo.com,bcd@yahoo.com


like in recepients i want to put semicolon or comma but both want to accept in coding..how to do this any idea?

protected static string mailSend(string FromAddress,string password,string[] ToAddress,string[] CcAddress,string[] BccAddress,string MessageBody,string Subject,string[] FileAttachment) 
        {
            try
            {
                MailMessage obj = new MailMessage();
                SmtpClient serverobj = new SmtpClient();

                serverobj.Credentials = new NetworkCredential(FromAddress, Password);
                serverobj.Port = 25;
                serverobj.Host = "smtp.gmail.com";
                serverobj.EnableSsl = true;
                obj = new MailMessage();
                obj.From = new MailAddress(FromAddress, FromAddress, System.Text.Encoding.UTF8);
                obj.Priority = MailPriority.High;
                obj.Subject = Subject.Trim();
                string date = DateTime.Now.ToString();
                obj.Body = MessageBody;
                obj.IsBodyHtml = true;


                if (ToAddress != null)
                {
                    foreach (string toAddr in ToAddress)
                        obj.To.Add(new MailAddress(toAddr));
                }



                if (CcAddress != null)
                {
                    foreach (string ccAddr in CcAddress)
                        obj.CC.Add(new MailAddress(ccAddr));
                }
                else
                    CcAddress = null;



                if (BccAddress != null)
                {
                    foreach (string bccAddr in BccAddress)
                        obj.Bcc.Add(new MailAddress(bccAddr));
                }
                else
                    BccAddress = null;


                if (Subject == string.Empty)
                    Subject = string.Empty;

                if (MessageBody == string.Empty)
                    MessageBody = string.Empty;


                if (Attachments != null && Attachments.Length > 0)
                    foreach (string _Attachment in Attachments)
                        obj.Attachments.Add(new System.Net.Mail.Attachment(_Attachment));
                else
                    Attachments = null;



                dbquery.InsertMail(FromAddress, ToAddress, CcAddress, BccAddress, Subject, MessageBody, Attachments);
                serverobj.Send(obj);
                return "Mail Sent Successfully";
            }

            catch (Exception ex)
            {
                return ex.Message;
            }
        }

推荐答案

要添加到MailAddressCollection的电子邮件地址.多个电子邮件地址必须用逗号分隔(,").
http://msdn.microsoft.com/en-us/library/ms144695 (v = VS.90).aspx [
The e-mail addresses to add to the MailAddressCollection. Multiple e-mail addresses must be separated with a comma character (",").
http://msdn.microsoft.com/en-us/library/ms144695(v=VS.90).aspx[^]

So, you can pass comma separated addresses. For semicolon, just replace it with comma and pass.


这篇关于如何使用分号接收电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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