403Webshell
Server IP : 54.37.205.81  /  Your IP : 216.73.216.76
Web Server : nginx/1.22.1
System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64
User : debian ( 1000)
PHP Version : 8.2.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/app.copyrightchain.it/copyrightchain_app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/app.copyrightchain.it/copyrightchain_app/emailService.ts
import { GoogleGenAI } from "@google/genai";
import { Language, Certificate } from "./types";

const ai = new GoogleGenAI({ apiKey: process.env.API_KEY });

export interface EmailDraft {
  subject: string;
  body: string;
  recipient: string;
}

export const draftNotificationEmail = async (
  type: 'generation' | 'verification' | 'anchoring_complete',
  cert: Certificate,
  lang: Language
): Promise<EmailDraft> => {
  const languageName = lang === 'it' ? 'Italiano' : 'English';
  
  let contextMsg = "";
  if (type === 'generation') contextMsg = "A new certificate has been successfully issued.";
  else if (type === 'verification') contextMsg = "An existing certificate has been verified by a third party.";
  else if (type === 'anchoring_complete') contextMsg = "The digital fingerprint has been successfully anchored to the Bitcoin Blockchain.";

  const prompt = `Generate a professional and formal email draft in ${languageName} for a digital copyright platform called "CertifyDraft".
  
  Context: ${contextMsg}
  
  Certificate Details:
  - ID: ${cert.id}
  - Title: ${cert.title}
  - Author: ${cert.author}
  - Date: ${new Date(cert.timestamp).toLocaleString()}
  - Hash: ${cert.fileHash}
  ${cert.bitcoinEvidence ? `- Bitcoin TxID: ${cert.bitcoinEvidence.txId}` : ''}
  
  The email should include:
  1. A clear subject line.
  2. A formal greeting.
  3. Details of the event.
  4. A reminder of the legal value and immutability provided by this step.
  5. A professional closing.
  
  Return the response in a structured text format starting with "SUBJECT:" and then "BODY:".`;

  try {
    const response = await ai.models.generateContent({
      model: 'gemini-3-flash-preview',
      contents: prompt,
    });

    const text = response.text || "";
    const subjectMatch = text.match(/SUBJECT:\s*(.*)/i);
    const bodyMatch = text.match(/BODY:\s*([\s\S]*)/i);

    return {
      subject: subjectMatch ? subjectMatch[1].trim() : "CertifyDraft Notification",
      body: bodyMatch ? bodyMatch[1].trim() : text,
      recipient: "user@example.com"
    };
  } catch (error) {
    console.error("Email drafting failed:", error);
    return {
      subject: "CertifyDraft Status Update",
      body: `Notification for Certificate ${cert.id}`,
      recipient: "user@example.com"
    };
  }
};

export const simulateEmailSend = async (draft: EmailDraft): Promise<boolean> => {
  // Nessun delay artificiale: in produzione sostituire con invio reale via backend.
  console.log(`[SIMULATED EMAIL SENT]
    To: ${draft.recipient}
    Subject: ${draft.subject}
    Body: ${draft.body.substring(0, 100)}...`);
  return true;
};

Youez - 2016 - github.com/yon3zu
LinuXploit