C# C:向个人邮件和团体邮件发送电子邮件(不适用于团体邮件)

C# C:向个人邮件和团体邮件发送电子邮件(不适用于团体邮件),c#,.net,email,C#,.net,Email,在ASP.NET/C应用程序mvc3中,我希望能够发送邮件 这是我正在使用的函数: public static void SendEmail(string fromEmail, string fromName, string toEmail, string toName, string subject, string emailBody, bool isBodyHtml, string[] attachments, string emailServer, int portNumber,

在ASP.NET/C应用程序mvc3中,我希望能够发送邮件

这是我正在使用的函数:

    public static void SendEmail(string fromEmail, string fromName, string toEmail, string toName, string subject, string emailBody, bool isBodyHtml, string[] attachments, string emailServer, int portNumber, string loginName, string loginPassword)
    {
        // setup email header
        System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();

        // Set the message sender
        // sets the from address for this e-mail message.
        mailMessage.From = new System.Net.Mail.MailAddress(fromEmail, fromName);
        // Sets the address collection that contains the recipients of this e-mail message.
        string[] toEmailList = toEmail.Split(',');
        string[] toNameList = toName.Split(',');
        for (int i = 0;i<toEmailList.Length;++i) 
        {
            mailMessage.To.Add(new System.Net.Mail.MailAddress(toEmailList[i],toNameList[i]));
        }
      //  mailMessage.To.(new System.Net.Mail.MailAddress(toEmail, toName));

        // sets the message subject.
        mailMessage.Subject = subject;
        // sets the message body.
        mailMessage.Body = emailBody;
        // sets a value indicating whether the mail message body is in Html.
        // if this is false then ContentType of the Body content is "text/plain".
        mailMessage.IsBodyHtml = isBodyHtml;

        // add all the file attachments if we have any
        if (attachments != null && attachments.Length > 0)
            foreach (string _Attachment in attachments)
                mailMessage.Attachments.Add(new System.Net.Mail.Attachment(_Attachment));

        // SmtpClient Class Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).
        System.Net.Mail.SmtpClient _SmtpClient = new System.Net.Mail.SmtpClient(emailServer);

        //Specifies how email messages are delivered. Here Email is sent through the network to an SMTP server.
        _SmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

        // Some SMTP server will require that you first authenticate against the server.
        // Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.
        System.Net.NetworkCredential _NetworkCredential = new System.Net.NetworkCredential(loginName, loginPassword);
        _SmtpClient.UseDefaultCredentials = false;

        _SmtpClient.Credentials = _NetworkCredential;
        _SmtpClient.Port = portNumber;
        //Let's send it
        try
        {
            _SmtpClient.Send(mailMessage);
            mailMessage.Dispose();
            _SmtpClient = null;
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }
对于个人电子邮件,一切都很好

问题是:

如果我发送此邮件的其中一封电子邮件是团体电子邮件,则不会发送给它

所谓群发邮件,我指的是一封附有多个联系人的邮件,当有人发送到该邮件时,他们都会收到该邮件

群电子邮件示例

如果有人发电子邮件给MyFamily@somedomain.com我的家人都收到了

我怎样才能使它适用于所有类型的电子邮件,而不仅仅是个人电子邮件


非常感谢您的帮助

我的个人谷歌应用程序域也有同样的问题。但问题在于组电子邮件的配置,而不是c代码

您是否检查了对群电子邮件的权限?通常,您可以定义谁可以向此群电子邮件发送电子邮件。因此,您必须使用正确的电子邮件地址或重新配置权限。通常,该组的所有成员都可以向该组发送电子邮件