Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs 12 is no longer supported and ses does not have permissions to write to bucket #45

Open
Jefdem1 opened this issue Oct 10, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Jefdem1
Copy link

Jefdem1 commented Oct 10, 2023

I updated the lambda node version to 14 and that part deploys successfully (Not sure if the code actually works or not on node14) then the next error i get is SES does not have permissions to write to the s3 bucket. It looks like the bucket policy is there so kind of stuck on that one. I'll try to troubleshoot some more but wanted to report it in case anything immediate stands out.

@Jefdem1 Jefdem1 added the bug Something isn't working label Oct 10, 2023
@davidgatti
Copy link
Member

O wow, a long time has passed. I won't have time to update the CFN to support the latest language, maybe some day but not now. And regarding access, check this section: https://github.com/0x4447/0x4447_product_s3_email#manual-work there is some manual work that you have to do to make it work.

@hyoretsu
Copy link

Oh, didn't notice this repo was dead for 2 years before the last commit... Seemed like it was the solution to create custom emails without paying heftier prices over at Gmail.

@Jefdem1
Copy link
Author

Jefdem1 commented Jan 21, 2024

After messing with this for a bit i realized it was pretty straight forward to setup aws simple email service. Was just a couple clicks to setup the identity and dns and then set a default rule that forwards everything to an S3 bucket. I wrote a simple boto3 python script to send mail but havent tested it yet. Was waiting for my limit approval which has now come through so maybe will test it soon. I'll post it once ive tested it.

@hyoretsu
Copy link

Yes I also managed that, but the problem comes after that. Viewing your emails from That S3 bucket

@Jefdem1
Copy link
Author

Jefdem1 commented Jan 21, 2024

So i have built and tested a solution for that. I have a javascript front end that hits an API gateway endpoint. The Api Gateway has a lambda proxy that triggers a lambda function to read the bucket. I need a better email formatter but its functional.

Lambda (Python)

import json
import boto3
s3 = boto3.client('s3')

def lambda_handler(event, context):
    get_last_modified = lambda obj: int(obj['LastModified'].strftime('%s'))
    Bucket = '<bucketname>'
    objs = s3.list_objects_v2(Bucket=Bucket)['Contents']
    emailid = int(event['queryStringParameters']['emailid'])
    last_added = [obj['Key'] for obj in sorted(objs, key=get_last_modified, reverse=True)][emailid]
    print(last_added)

    data = s3.get_object(Bucket=Bucket, Key=last_added)
    contents = data['Body'].read()


    return { 'statusCode': 200,  'body': json.dumps(contents.decode("utf-8")), 'headers': {'Content-Type': 'application/json','Access-Control-Allow-Origin': '*','Access-Control-Allow-Methods':'*'}}

Javascript website (S3 static hosted website)

<html>
<head>
<title>
</title>
</head>
  <script>
    function GetEmail()
    {
      let url = "<api gateway url>?emailid=0"
      var request = new XMLHttpRequest()
      request.open('GET', url, true)
      request.onload = function()
      {
          var data = this.response
                                                                                                  
         if(request.status >= 200 && request.status < 400)
         {
           document.getElementById('EmailTxtArea').innerHTML = data
         }
         else
         {
           console.log("error")
         }
                                                                                                 
     }
      
      request.send()
      
    }

  </script>
<body>

  <input type="button" onclick=GetEmail() value="Get Email">
<br>
  <div id=email></div>
  <br>
  <input type=text id=Email style='width: 800px; visibility: hidden;'>
  <br>
  <textarea id="EmailTxtArea" rows="4" cols="50">
</textarea>
</body>
</html>

@cariaso
Copy link

cariaso commented Jan 21, 2024

Perhaps of interest
https://github.com/mewa/s3abird

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

4 participants