import { loadCredentials } from "../lib/credentials.js";
import { sendEmail } from "../lib/smtp.js";
export async function emailSend(params) {
    const result = await loadCredentials(params.accountId);
    if ("error" in result)
        throw new Error(result.error);
    const { config, password } = result.credentials;
    try {
        const { messageId } = await sendEmail(config, password, {
            to: params.to,
            subject: params.subject,
            body: params.body,
            html: params.html,
        });
        return `Email sent to ${params.to} (Message-ID: ${messageId})`;
    }
    catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        if (config.agentAddress !== config.email) {
            throw new Error(`${msg} — Note: sending as ${config.agentAddress} (authenticated as ${config.email}). If your provider doesn't allow sending as this alias, check your catchall or alias settings.`);
        }
        throw err;
    }
}
//# sourceMappingURL=email-send.js.map