邮戳SendMessageAsync消息未发送电子邮件c#

时间:2016-08-29 07:00:47

标签: c# postmark

以下是我使用邮戳发送电子邮件的代码段

public async Task<bool> SendEmail(CustomMailMessage mailMessage)

{

    HeaderCollection headers = new HeaderCollection();

    if (mailMessage.Headers != null)

    {

        var items = mailMessage.Headers.AllKeys.SelectMany(mailMessage.Headers.GetValues, (k, v) => new { key = k, value = v });

        foreach (var item in items)

        {

            headers.Add(item.key, item.value);

        }

    }

    var message = new PostmarkDotNet.PostmarkMessage()
    {
        To = mailMessage.To,
        Cc = mailMessage.Cc,
        Bcc = mailMessage.Bcc,
        From = mailMessage.FromName + "<" + mailMessage.From + ">",
        TrackOpens = true,
        Subject = mailMessage.Subject,
        TextBody = mailMessage.Body,
        HtmlBody = mailMessage.HtmlBody,
        Headers = headers,
    };


    if (mailMessage.AttachmentsPath != null)
    {
        foreach (string file in mailMessage.AttachmentsPath)
        {
            var imageContent = File.ReadAllBytes(file);
            message.AddAttachment(imageContent, Path.GetFileName(file), MimeMapping.GetMimeMapping(file), null);

        }
    }
    var client = new PostmarkClient(ConfigurationSettings.AppSettings["postmarkServerToken"].ToString(), "https://api.postmarkapp.com", 30);

    var sendResult = await client.SendMessageAsync(message);

    if (sendResult.Status== PostmarkStatus.Success)
    {
        return true;
    }
    else
    {
        return false;
    }
}

当我尝试发送电子邮件时“ var sendResult = await client.SendMessageAsync(message); ”在点击此行时没有得到任何响应,并且当再次发送邮件时收到消息“{{ 1}}。“

请帮助

0 个答案:

没有答案