繁体   English   中英

AWS SES C#sendemailasync任务被取消

[英]AWS SES c# sendemailasync task gets cancelled

我正在使用asp.net core 2.0,并尝试使用适用于.net的AWS开发工具包通过AWS SES发送电子邮件。

我使用了非常简单的代码来执行此操作,但是由于某些原因,当我尝试发送时,异步任务被取消了。 有什么明显的我想念的地方吗? 我从此代码中获得的异常显示“操作已取消”。 如果我深入研究总体异常,它特别表示该任务已取消。

这是我的代码。

public async Task<transactionresponse> sendemail(string subject, string message, string sender, string replyto, List<string> receivers, string[] attachment = null)
    {
        transactionresponse tr = new transactionresponse();
        try
        {
            AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(RegionEndpoint.USWest2);
            sender = (sender == "" ? config.GetSection("appsettings:appemail").Value : sender);
            var dest = new Destination
            {
                ToAddresses = receivers,
            };

            var from = sender;
            var messagesubject = new Content(subject);
            var body = new Body(new Content(message));
            var msg = new Message(messagesubject, body);

            var request = new SendEmailRequest
            {
                Destination = dest,
                Message = msg,
                Source = from
            };
            SendEmailResponse sendit = await client.SendEmailAsync(request);
        }
        catch (Exception ex)
        {
            tr.errors = new string[] { ex.ToString() };
            tr.message = ex.Message;
            tr.iserror = true;
        }
        return tr;
    }

这是例外:

“ System.OperationCanceledException:操作已取消。\\ r \\ n位于System.Net.Http.HttpClient.HandleFinishSendAsyncError(异常e,CancellationTokenSource cts)\\ r \\ n
在System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(任务1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)\\r\\n
at System.Net.Http.HttpClient.GetStringAsyncCore(Task
1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)\\r\\n
at System.Net.Http.HttpClient.GetStringAsyncCore(Task
1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)\\r\\n
at System.Net.Http.HttpClient.GetStringAsyncCore(Task
1 getTask)\\ r \\ n在Amazon.Runtime.Internal.Util.AsyncHelpers。<> c__DisplayClass1_1 1.<<RunSync>b__0>d.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n
at Amazon.Runtime.Internal.Util.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop() in E:\\\\JenkinsWorkspaces\\\\v3-trebuchet-release\\\\AWSDotNetPublic\\\\sdk\\\\src\\\\Core\\\\Amazon.Runtime\\\\Internal\\\\Util\\\\_mobile\\\\AsyncHelpers.cs:line 142\\r\\n
at Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync[T](Func
1.<<RunSync>b__0>d.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n
at Amazon.Runtime.Internal.Util.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop() in E:\\\\JenkinsWorkspaces\\\\v3-trebuchet-release\\\\AWSDotNetPublic\\\\sdk\\\\src\\\\Core\\\\Amazon.Runtime\\\\Internal\\\\Util\\\\_mobile\\\\AsyncHelpers.cs:line 142\\r\\n
at Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync[T](Func
1.<<RunSync>b__0>d.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n
at Amazon.Runtime.Internal.Util.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop() in E:\\\\JenkinsWorkspaces\\\\v3-trebuchet-release\\\\AWSDotNetPublic\\\\sdk\\\\src\\\\Core\\\\Amazon.Runtime\\\\Internal\\\\Util\\\\_mobile\\\\AsyncHelpers.cs:line 142\\r\\n
at Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync[T](Func
E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Runtime \\ Internal \\ Util \\ _mobile \\ 1.<<RunSync>b__0>d.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n
at Amazon.Runtime.Internal.Util.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop() in E:\\\\JenkinsWorkspaces\\\\v3-trebuchet-release\\\\AWSDotNetPublic\\\\sdk\\\\src\\\\Core\\\\Amazon.Runtime\\\\Internal\\\\Util\\\\_mobile\\\\AsyncHelpers.cs:line 142\\r\\n
at Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync[T](Func
1任务)处AsyncHelpers.cs:第87行\\ r \\ n

在E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Util \\ AWSSDKUtils.cs:line 1000 \\ r中的Amazon.Util.AWSSDKUtils.DownloadStringContent(Uri uri,TimeSpan timeout,IWebProxy代理)中\\ n
在E. \\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Util \\ _bcl + coreclr \\ EC2InstanceMetadata.cs中的Amazon.Util.EC2InstanceMetadata.GetItems(String relativeOrAbsolutePath,Int32 trys,Boolean slurp)中: 513行\\ r \\ n
在E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Util \\ _bcl + coreclr \\ EC2InstanceMetadata.cs:line 311 \\ r \\ n中的Amazon.Util.EC2InstanceMetadata.get_IAMSecurityCredentials()
在E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Runtime \\ Credentials \\ _bcl + coreclr \\ DefaultInstance \\ AWSCredentials.cs:line 142 \\ r中的Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
在E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Runtime \\ Credentials \\ _bcl + coreclr \\ DefaultInstanceProfileAWSCredentials.cs:line 88 \\ r \\ n中的Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
在E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Runtime \\ Credentials \\ _bcl + coreclr \\ DefaultInstance \\ AWSCredentials.cs:line 106 \\ r中的Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
在E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Runtime \\ Pipeline \\ Handlers \\ CredentialsRetriever.cs:line中的Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync [T](IExecutionContext executeContext)中90 \\ r \\ n
E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\中的Amazon.Runtime.Internal.RetryHandler.InvokeAsync [T](IExecutionContext executeContext)\\ r \\ n在Amazon.Runtime.Internal.RetryHandler.InvokeAsync [T](IExecutionContext executeContext)中Amazon.Runtime.Internal.CallbackHandler.InvokeAsync的AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Runtime \\ Pipeline \\ RetryHandler \\ RetryHandler.cs:line 137 \\ r \\ n [T](IExecutionContext executeContext)\\ r \\ n
在Amazon.Runtime.Internal.CallbackHandler.InvokeAsync [T](IExecutionContext executeContext)\\ r \\ n在Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync [T](IExecutionContext executeContext)\\ r \\ n在Amazon.Runtime.Internal.MetricsHandler .InvokeAsync [T](IExecutionContext executeContext)\\ r \\ n
在webworxfive.Helpers.messaging.sendemail(在messageting.cs:第48行中,为String(主题,String消息,String发送者,String Replyto,List`1接收者,String []附件))

好吧,我自己弄清楚了。 显然,我的应用程序没有从aws sdk配置文件设置中获取访问密钥和访问密码。 当我将其添加到我的appsettings中并将其调用到发送的代码中时。 我似乎记得当您安装Visual Studio插件时,它总是会抓住选定的配置文件密钥。 也许我记错了。

感谢那些发表评论的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM