[英]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(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)\\r\\n
at System.Net.Http.HttpClient.GetStringAsyncCore(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)\\r\\n
1 getTask)\\ r \\ n在Amazon.Runtime.Internal.Util.AsyncHelpers。<> c__DisplayClass1_1
at System.Net.Http.HttpClient.GetStringAsyncCore(Task1.<<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](Func1.<<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](Func1.<<RunSync>b__0>d.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n
E:\\ JenkinsWorkspaces \\ v3-trebuchet-release \\ AWSDotNetPublic \\ sdk \\ src \\ Core \\ Amazon.Runtime \\ Internal \\ Util \\ _mobile \\
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](Func1.<<RunSync>b__0>d.MoveNext()\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n
1任務)處AsyncHelpers.cs:第87行\\ 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.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.