public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.SimpleEmail.Model.ListVerifiedEmailAddressesRequest(); CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); }
public IEmailSendResult Send(IEmailMessage message) { var asmRequest = new ASM.ListVerifiedEmailAddressesRequest(); var ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(_awsAccessKey, _awsSecretKey, RegionEndpoint.USEast1); try { var awsConfirmResponse = ses.ListVerifiedEmailAddresses(); var verifiedEmails = awsConfirmResponse.VerifiedEmailAddresses; if (verifiedEmails.Contains(_contactEmail) && verifiedEmails.Contains(_contactFromEmail)) { var emailRequest = new ASM.SendEmailRequest(); var destination = new ASM.Destination(); destination.ToAddresses.Add(_contactEmail); var awsMessage = CreateMessage(message); emailRequest.Destination = destination; emailRequest.Message = awsMessage; emailRequest.Source = _contactFromEmail; emailRequest.ReplyToAddresses = new List <string>() { message.Email }; var awsSendResponse = ses.SendEmail(emailRequest); var messageId = awsSendResponse.MessageId; return(new EmailSendResult { Success = (awsSendResponse.HttpStatusCode == System.Net.HttpStatusCode.OK), MessageId = awsSendResponse.MessageId, Message = string.Empty }); } else { return(new EmailSendResult { Success = false, MessageId = string.Empty, Message = string.Format("Unable to verify email address. {0} or {1}", _contactEmail, _contactFromEmail) }); } } catch (Exception ex) { return(new EmailSendResult { Success = false, MessageId = string.Empty, Message = ex.Message }); } }
private Amazon.SimpleEmail.Model.ListVerifiedEmailAddressesResponse CallAWSServiceOperation(IAmazonSimpleEmailService client, Amazon.SimpleEmail.Model.ListVerifiedEmailAddressesRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Email Service (SES)", "ListVerifiedEmailAddresses"); try { #if DESKTOP return(client.ListVerifiedEmailAddresses(request)); #elif CORECLR return(client.ListVerifiedEmailAddressesAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
public List<string> ListVerifiedEmailAddresses() { Amazon.SimpleEmail.Model.ListVerifiedEmailAddressesRequest request = new Amazon.SimpleEmail.Model.ListVerifiedEmailAddressesRequest(); Amazon.SimpleEmail.Model.ListVerifiedEmailAddressesResponse response = new Amazon.SimpleEmail.Model.ListVerifiedEmailAddressesResponse(); List<string> verifiedEmailList = new List<string>(); response = client.ListVerifiedEmailAddresses(request); if (client != null) { if (response.ListVerifiedEmailAddressesResult != null) { if (response.ListVerifiedEmailAddressesResult.VerifiedEmailAddresses != null) { verifiedEmailList.AddRange(response.ListVerifiedEmailAddressesResult.VerifiedEmailAddresses); } } } return verifiedEmailList; }