2016-04-05 4 views

Antwort

4

Ich habe es herausgefunden. Ich gestehe, dass die Dokumentation von Amazon etwas dicht ist. Hoffe das hilft jemand anderem!

AWSSESSendEmailRequest *awsSESSendEmailRequest = [AWSSESSendEmailRequest new]; 
awsSESSendEmailRequest.source = @"[email protected]"; 
AWSSESDestination *awsSESDestination = [AWSSESDestination new]; 
awsSESDestination.toAddresses = [NSMutableArray arrayWithObjects:@"[email protected]",nil]; 
awsSESSendEmailRequest.destination = awsSESDestination; 

AWSSESMessage *awsSESMessage = [AWSSESMessage new]; 
AWSSESContent *awsSESSubject = [AWSSESContent new]; 
awsSESSubject.data = @"Subject goes here"; 
awsSESSubject.charset = @"UTF-8"; 

awsSESMessage.subject = awsSESSubject; 
AWSSESContent *awsSESContent = [AWSSESContent new]; 
awsSESContent.data = @"Message goes here"; 
awsSESContent.charset = @"UTF-8"; 

AWSSESBody *awsSESBody = [AWSSESBody new]; 
awsSESBody.text = awsSESContent; 
awsSESMessage.body = awsSESBody; 
awsSESSendEmailRequest.message = awsSESMessage; 


AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:@"ACCESS-KEY" 
                            secretKey:@"SECRET-KEY"]; 
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2 
                    credentialsProvider:credentialsProvider]; 
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration; 

[[AWSSES defaultSES] sendEmail:awsSESSendEmailRequest completionHandler:^(AWSSESSendEmailResponse * _Nullable response, NSError * _Nullable error) { 
    if (error) 
    { 
     // error 
    } 
    else 
    { 
     // success 
    } 
}]; 
+0

Danke für den obigen Code. Ich habe eine andere Anforderung, die die Datei über AWS SES senden muss. Ich habe erfahren, dass ich die sendRawEmail-API für dasselbe verwenden muss. Kann jemand mit Beispielcode-Snippet helfen? – Ganesh

0

Das Code-Snippet von E-Mail senden in Swift 3.0 unten.

let serviceRegionType = AWSRegionType.usEast1 
    let credentialsProvider = AWSStaticCredentialsProvider.init(accessKey: "access", secretKey: "secret") 
    let configuration = AWSServiceConfiguration(region: serviceRegionType, credentialsProvider: credentialsProvider) 
    AWSServiceManager.default().defaultServiceConfiguration = configuration 

    let subject = AWSSESContent() 
    subject?.data = "Subject" 
    subject?.charset = "UTF-8" 

    let messageBody = AWSSESContent() 
    messageBody?.data = "Sample Message body" 
    messageBody?.charset = "UTF-8" 

    let body = AWSSESBody() 
    body?.text = messageBody 

    let theMessage = AWSSESMessage() 
    theMessage?.subject = subject 
    theMessage?.body = body 

    let destination = AWSSESDestination() 
    destination?.toAddresses = ["toaddress"] 

    let send = AWSSESSendEmailRequest() 
    send?.source = "source mail" 
    send?.destination = destination 
    send?.message = theMessage 

    AWSSES.default().sendEmail(send!) { (response:AWSSESSendEmailResponse?, mailError: Error?) in 
     print(mailError?.localizedDescription) 
     if ((response?.messageId) != nil) { 
      print("Mail has delivered succesfully") 
     } else { 
      print("Mail has failed to delivered") 
     } 
    } 
Verwandte Themen