mailkit sendMail doubts



我有一个服务器在云(asp.net),我安装mailkit提供我的客户从我的应用程序发送电子邮件与他们自己的电子邮件帐户。

我的一个问题是他可以发送3封邮件,然后下一封邮件被服务器拒绝:

"消息:连接尝试失败,因为被连接的一方失败了一段时间后没有适当回应,或建立联系失败,因为连接的主机未能响应213.190.193.29:25"

另一个问题是,他们给他发邮件,他收到一个"垃圾邮件"。

你能帮我吗?

    {
        emailID = "";
        // Nova Mensagem 
        var message = new MimeMessage();
        try
        {
            // Acede aos parâmetros do email caso este seja do gestobrigweb gmail.com
            if (emailSettings.email == "gestobrigweb@gmail.com") {
                EmailProvider provider = new EmailProviders().GetEmailProvider(Convert.ToInt32(ConfigurationManager.AppSettings["gestObrigWebProviderID"]));
                if (emailSettings.provider == null)
                    emailSettings.provider = provider;
            }
            // UserName
            string userName = emailSettings.email;   
            // Password
            if (userPass == "")
                userPass = cripter.Decrypt(emailSettings.pass);
            // From
            message.From.Add(new MailboxAddress(emailSettings.email, emailSettings.email));
            // TO
            if (recipient.Contains(";"))
                foreach (string recipt in recipient.Split(';'))
                    message.To.Add(new MailboxAddress(recipt, recipt));
            else
                if (recipient.Contains(","))
                    foreach (string recipt in recipient.Split(','))
                        message.To.Add(new MailboxAddress(recipt, recipt));
                else
                  message.To.Add(new MailboxAddress(recipient, recipient));

            // Se Assume CC
            if (assumeCC)
                message.Cc.Add(new MailboxAddress(emailSettings.email,emailSettings.email));
            // Destinatário
            if (cc != "")
            {
                if (cc.Contains(";"))
                    foreach (string emailCC in cc.Split(';'))
                    message.Cc.Add(new MailboxAddress(emailCC,emailCC));
                else
                    message.Cc.Add(new MailboxAddress(cc, cc));
            }
            // Assunto
            message.Subject = subject;
            // Body (Mensagem)
            var bodyBuilder = new BodyBuilder();
            bodyBuilder.HtmlBody = body;
            message.Body = bodyBuilder.ToMessageBody();
            // Envio
            using (var client = new SmtpClient())
            {
                // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                client.Connect(emailSettings.emailServer, emailSettings.serviceType, false);
                // Note: since we don't have an OAuth2 token, disable
                // the XOAUTH2 authentication mechanism.
                client.AuthenticationMechanisms.Remove("XOAUTH2");
                // Note: only needed if the SMTP server requires authentication
                client.Authenticate(userName, userPass);
                client.Send(message);
                client.Disconnect(true);
                return true;
            }
        }

相关内容

  • 没有找到相关文章

最新更新