Письмо не отправлено с аккаунта - PullRequest
0 голосов
/ 24 сентября 2019

У меня есть адрес электронной почты, который я получил от fatcow.Я использую это электронное письмо для отправки почты из моего приложения любому, кто создает пользователя из моего приложения.Я разработал приложение на C #.Мой код:

    public static async Task SendMailAsync(string emailSendTo, string emailAddress, string password, int emailKeyID, Dictionary<string, string> additionalInfo = null,string Username =null,string pdfFileName = "")
    {
        NetworkCredential login;
        SmtpClient client;
        MailMessage msg;
        clsEmail clsEmail = new clsEmail();
        var obj = clsEmail.GetByApplicationKey(emailKeyID);

        login = new NetworkCredential(emailAddress, password);
        //client = new SmtpClient("smtp.gmail.com");
        //client.Port = Convert.ToInt32(587);

        client = new SmtpClient("smtp.fatcow.com");
        client.Port = Convert.ToInt32(465);

        client.EnableSsl = false;
        client.UseDefaultCredentials = false;
        client.Credentials = login;
        msg = new MailMessage { From = new MailAddress(emailAddress, obj.DisplayText, Encoding.UTF8) };
        msg.To.Add(new MailAddress(emailSendTo));
        msg.Subject = obj.DisplayText;

        msg.Body = GetMsgBody(emailKeyID, obj, emailSendTo, additionalInfo, Username);

        Attachment attachment = null;
        if (!string.IsNullOrEmpty(pdfFileName))
        {
            attachment = new Attachment(pdfFileName, MediaTypeNames.Application.Pdf);
            msg.Attachments.Add(attachment);
        }

        msg.BodyEncoding = Encoding.UTF8;
        msg.IsBodyHtml = false;
        msg.Priority = MailPriority.Normal;
        msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
        client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
        string userState = "Sending...";
        await Task.Run(() => client.SendAsync(msg, userState));
    }

    private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
    { 
        if (e.Cancelled)
        {
            //canceled
            string status = Convert.ToString(SendMailStatus.Cancelled);
            string[] lines = { "Status", status };
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "Static\\mailnote.txt"))                
            {
                foreach (string line in lines)
                {
                    file.WriteLine(line);
                }
            }
        }
        if (e.Error != null)
        {
            string status = Convert.ToString(SendMailStatus.Error);
            string[] lines = { "Status", status};
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "Static\\mailnote.txt"))
            {
                foreach (string line in lines)
                {
                    file.WriteLine(line);
                }
            }
        }
        else
        {
            string status = Convert.ToString(SendMailStatus.successfully);
            string[] lines = { "Status", status };
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "Static\\mailnote.txt"))
            {
                foreach (string line in lines)
                {
                   file.WriteLine(line);
                }
            }

        }
    }

С URL: https://www.opendental.com/manual/emailerrors.html Я получил SMTP-клиент и порт.

Я всегда получаю сообщение об ошибке "Синтаксическая ошибка, команда не распознана. Ответ сервера был:" и электронное письмо не отправлено.При отправке электронной почты из учетной записи Gmail почта отправляется.Где я делаю не так?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...