Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AWS iOS SDK:通过AWSS发送电子邮件_Ios_Objective C_Aws Sdk - Fatal编程技术网

AWS iOS SDK:通过AWSS发送电子邮件

AWS iOS SDK:通过AWSS发送电子邮件,ios,objective-c,aws-sdk,Ios,Objective C,Aws Sdk,是否有人有使用最新的Amazon AWS SDK 2.3.6通过SES SMTP发送电子邮件的经验?我目前有一个api密钥、密码和smtp_url 谢谢 刚刚想好了。我承认亚马逊的文档有点密集。希望这对其他人有帮助 AWSSESSendEmailRequest *awsSESSendEmailRequest = [AWSSESSendEmailRequest new]; awsSESSendEmailRequest.source = @"source@email"; AWSSESDestinat

是否有人有使用最新的Amazon AWS SDK 2.3.6通过SES SMTP发送电子邮件的经验?我目前有一个api密钥、密码和smtp_url


谢谢

刚刚想好了。我承认亚马逊的文档有点密集。希望这对其他人有帮助

AWSSESSendEmailRequest *awsSESSendEmailRequest = [AWSSESSendEmailRequest new];
awsSESSendEmailRequest.source = @"source@email";
AWSSESDestination *awsSESDestination = [AWSSESDestination new];
awsSESDestination.toAddresses = [NSMutableArray arrayWithObjects:@"to@email",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
    }
}];

我刚想出来。我承认亚马逊的文档有点密集。希望这对其他人有帮助

AWSSESSendEmailRequest *awsSESSendEmailRequest = [AWSSESSendEmailRequest new];
awsSESSendEmailRequest.source = @"source@email";
AWSSESDestination *awsSESDestination = [AWSSESDestination new];
awsSESDestination.toAddresses = [NSMutableArray arrayWithObjects:@"to@email",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
    }
}];

下面是Swift 3.0中发送电子邮件的代码片段

    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")
        }
    }

下面是Swift 3.0中发送电子邮件的代码片段

    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")
        }
    }

补充一下unicornherder的答案:你的代码在我的iOS应用程序中运行良好。然而,因为我的应用程序用户是通过Cognito认证的,所以我不需要您的代码来设置AWSStaticCredentialsProvider。根据示例代码,这已经发生在我的AppDelegate中


然而,我确实需要给我的Cognito授权用户使用SES的权限。最后一步是通过向authUser角色添加权限来完成的

补充unicornherder的答案:您的代码在我的iOS应用程序中运行良好。然而,因为我的应用程序用户是通过Cognito认证的,所以我不需要您的代码来设置AWSStaticCredentialsProvider。根据示例代码,这已经发生在我的AppDelegate中


然而,我确实需要给我的Cognito授权用户使用SES的权限。最后一步是通过向authUser角色添加权限来完成的

谢谢上面的代码。我有另一个要求,需要通过AWS SES发送文件。我知道我们必须使用sendRawEmail API来实现同样的功能。任何人都可以帮助处理示例代码段吗?谢谢上面的代码。我有另一个要求,需要通过AWS SES发送文件。我知道我们必须使用sendRawEmail API来实现同样的功能。任何人都可以帮助处理示例代码段吗?