SmtpException:语法错误,命令无法识别

时间:2017-10-26 21:11:09

标签: amazon-web-services asp-classic asp.net-core-2.0

这会发送一封电子邮件......

Sub SendEmailV2(cdoMessage)

    Dim iConf, Flds

    Set iConf = CreateObject("CDO.Configuration")

    Set Flds = iConf.Fields

    Const cdoSendUsingPort = 2

    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort 
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "email-smtp.us-east-1.amazonaws.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic 
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyUsername"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPasswors"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        .Update
    End With

    cdoMessage.Configuration = iConf
    cdoMessage.Send

End Sub

这不......

public async Task Send(Message message)
        {
            using (var smtp = new SmtpClient())
            {
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.Host = config.Host; // same host
                smtp.Port = config.Port; // same port
                smtp.Credentials = new NetworkCredential(config.Username, config.Password); // same username and password
                smtp.EnableSsl = true;

                var msg = new MailMessage
                {
                    Body = message.Body,
                    Subject = message.Subject,
                    From = new MailAddress(config.FromAddress)
                };

                msg.To.Add(message.To);

                await smtp.SendMailAsync(msg);
            }
        }

为什么相同的细节不起作用?它停留在ConnectAndHandshakeAsyncResult

我应该使用ASP classic创建粗略的web api并从.net发送电子邮件吗?

1 个答案:

答案 0 :(得分:0)

我用过这个......

https://github.com/jstedfast/MailKit

我看过一些关于.net的SmtpClient在需要TLS时效果不佳的帖子。

   public async Task Send(Message message)
    {
        var emailMessage = new MimeMessage();

        emailMessage.From.Add(new MailboxAddress(config.FromName, config.FromAddress));
        emailMessage.To.Add(new MailboxAddress(message.To));
        emailMessage.Subject = message.Subject;
        emailMessage.Body = new TextPart("plain") { Text = message.Body };

        using (var client = new SmtpClient())
        {
            await client.ConnectAsync(config.Host, config.Port, true);

            await client.AuthenticateAsync(config.Username, config.Password);

            await client.SendAsync(emailMessage);

            await client.DisconnectAsync(true);
        }
    }