Dear all, good day.
I would be very grateful if someone can give me some pointers.
I am trying to send a test email from this app via python/capnpn.
I have created a send mail as per the sandstorm documentation which looks something like this:
import socket
import capnp
import sandstorm_http_bridge_capnp
import hack_session_capnp
def send_email(session_id, submission_details):
try:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("/tmp/sandstorm-api")
client = capnp.TwoPartyClient(s)
bridge =
client.ez_restore().cast_as(sandstorm_http_bridge_capnp.SandstormHttpBridge)
session_context = bridge.get_session_context({"id":
session_id}).wait().context
email_cap =
session_context.cast_as(hack_session_capnp.HackSessionContext)
req = email_cap.send_request()
email = req.email
setattr(email, 'from',
email_cap.getUserAddress().wait())
email.to = ['a...@hrbr.life']
email.subject = 'New Submission'
email.text = f"New submission received:
{submission_details}"
req.send().wait()
print("Email sent successfully.")
except Exception as e:
print(f"Failed to send email: {e}", exc_info=True)
I have also tried to initiate capnp in my app by starting it with
the following:
import os
import socket
import capnp
from flask import Flask, render_template, request, redirect,
url_for, flash
from werkzeug.utils import secure_filename
import hashlib
from extensions import db
from models import Submission
# Initialize Cap'n Proto event loop for Sandstorm
capnp.remove_event_loop()
capnp.create_event_loop(threaded=True)
# Load the relevant interface descriptors from the current
sandstorm bundle.
bridge =
capnp.load("/opt/sandstorm/latest/usr/include/sandstorm/sandstorm-http-bridge.capnp",
imports=[
"/opt/sandstorm/latest/usr/include",
]
)
util =
capnp.load("/opt/sandstorm/latest/usr/include/sandstorm/util.capnp",
imports=[
"/opt/sandstorm/latest/usr/include",
]
)
powerbox =
capnp.load("/opt/sandstorm/latest/usr/include/sandstorm/powerbox.capnp",
imports=[
"/opt/sandstorm/latest/usr/include",
]
)
identity =
capnp.load("/opt/sandstorm/latest/usr/include/sandstorm/identity.capnp",
imports=[
"/opt/sandstorm/latest/usr/include",
]
)
grain =
capnp.load("/opt/sandstorm/latest/usr/include/sandstorm/grain.capnp",
imports=[
"/opt/sandstorm/latest/usr/include",
]
)
hack_session =
capnp.load("/opt/sandstorm/latest/usr/include/sandstorm/hack-session.capnp",
imports=[
"/opt/sandstorm/latest/usr/include",
]
)
pkgdef = capnp.load("/sandstorm-pkgdef.capnp",
imports=[
"/opt/sandstorm/latest/usr/include",
]
)
capnpip =
capnp.load("/opt/sandstorm/latest/usr/include/sandstorm/ip.capnp",
imports=[
"/opt/sandstorm/latest/usr/include",
]
)
# Assuming capnp schema files are located as per the example,
importing Sandstorm's capnp files
import sandstorm_http_bridge_capnp
import hack_session_capnp
That being said, I am obviously doing something wrong because I
am always getting stuck with messages in the console that
essentially say that hack sessiion and http brindge are failing to
load.
It's as if I'm missing a step somewhere to compile python modules
out of the capnp files (ps: ive tried that too, and failed
miserably).
PS I am using vagrant-spk with a custom stack that is included in
the repo and is desitined to be temporarily placed in the vagrant
stack directory I guess. It's the python stack with Sqlite instead
of mysql and hence all the mysql stuff removed.
Here is the repo:
https://app.hrbr.life/shared/ytWaJWurdWB8gJrks4e7nTdtRp5Ua_AcvikcZyD9daB