'How to add AWS SES (Simple Email Service) to .net 6 program.cs
I need to send emails in .net 6 using Amazon SES.
In .net 5 and before you needed to add this to startup.cs
// Amazon SES
services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
services.AddAWSService<IAmazonSimpleEmailService>();
services.AddSingleton<IEmailService, CSharpAwsSesServiceHelper.EmailService.AwsEmailService>();
services.Configure<AwsEmailServiceOptions>(Configuration.GetSection(nameof(AwsEmailServiceOptions)))
.AddSingleton(x => x.GetRequiredService<IOptions<AwsEmailServiceOptions>>().Value);
In .net 6 there is no Startup.cs, it has been replaced and simplified in program.cs.
However, there's no Configuration object by default in program.cs like there is in Startup.cs, and this doesn't work (error 'Configuration does not contain GetAWSOptions())
I've searched for a sample project or guidance, eg https://aws.amazon.com/blogs/developer/net-6-on-aws/ https://github.com/aws-samples/aws-net-guides/tree/master/RuntimeSupport/dotnet6 https://jasonwatmore.com/post/2020/11/28/net-core-c-aws-ses-send-email-via-smtp-with-aws-simple-email-service
But can't find the .net 6 version of this code.
Anybody know what best practice is here / how to make this work?
Thanks.
UPDATE
I've copied all using statements from Startup.cs to Program.cs - this is not the problem.
I then copied the service builder across (changing services. to builder.Services.) I get the error listed above due to the lack of a Configuration object in program.cs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|