我曾经有一个API,用于连接到发送邮件的邮件服务。该邮件服务提供的参数之一是附件流。 sendMail函数是同步的,所以我没有任何问题
除了我们试图创建一个与上面类似的新API。原来的是常规的.NET,而我们正在使用的新的则是.NET Core 2,0。这意味着,连接到该服务后,一切都会变得异步。
我想让我的服务这样运行
try
{
// Send the email.
var result = mailService.SendMailWithMessageAsync(emailMessage, "DefaultMail").Result;
}
catch (Exception ex)
{
string error = ex.ToString();
}
我不支持内存超时。如果我不使用任何附件,我的邮件服务将正常工作。
有什么建议吗?
答案 0 :(得分:0)
似乎这是一个.NET Core 2.0问题,我使用.NET Framework 4.6.1创建了相同的控制台程序,而我对此没有任何问题。我连接的邮件服务是由另一个小组开发的,现在我发现使用.NET Core 2.0而不是.NET Standard 4.6.1
时遇到了麻烦using System;
using System.IO;
using System.Threading.Tasks;
using ConnectedMailService;
namespace MailSender
{
class Program
{
static void Main(string[] args)
{
try
{
MainAsync(args).GetAwaiter().GetResult();
Console.WriteLine("Email Send End!");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
Console.ReadKey();
}
static async Task MainAsync(string[] args)
{
Console.WriteLine("Email Send Start!");
MailServiceClient mailService = new ConnectedMailService.MailServiceClient();
EMailMessage emailMessage = new EMailMessage();
emailMessage.Subject = "Email Subject Test";
emailMessage.To = new EmailRecipient[1];
emailMessage.To[0] = new EmailRecipient();
emailMessage.To[0].recipientEmail = "nino@mail.com";
emailMessage.From = "test@mail.com";
emailMessage.Body = "Email Body Test.";
StreamAttachment streamAttachment = new StreamAttachment();
streamAttachment.attachment = new MemoryStream(new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35 });
streamAttachment.fileName = "12345.txt";
emailMessage.streamAttachments = new StreamAttachment[1];
emailMessage.streamAttachments[0] = streamAttachment;
var retVal = await mailService.SendMailWithMessageAsync(emailMessage, "DefaultMail");
}
}
}
你们遇到过类似的事情吗?