电子邮件不是从Fatcow帐户发送的

时间:2019-09-24 18:17:34

标签: c# email-integration

我有一个来自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帐户发送电子邮件后,即会发送邮件。我在哪里做错了?

0 个答案:

没有答案