SendTestCore composes and sends (or HITL-holds) a platform test email to the agent's own address. HTTP-free; shared by the legacy handler and the v1 layer. The caller has already authed, resolved + owned the agent, domain-verified, and run the message-send cap.
(ctx context.Context, agent *identity.AgentIdentity)
| 1228 | // layer. The caller has already authed, resolved + owned the agent, |
| 1229 | // domain-verified, and run the message-send cap. |
| 1230 | func (a *API) SendTestCore(ctx context.Context, agent *identity.AgentIdentity) (*OutboundResult, *OutboundError) { |
| 1231 | envelopeFrom := fmt.Sprintf("noreply@%s", a.fromDomain) |
| 1232 | headerFrom := fmt.Sprintf("%q <%s>", "e2a", envelopeFrom) |
| 1233 | to := []string{agent.EmailAddress()} |
| 1234 | subject := "Test email from e2a" |
| 1235 | body := fmt.Sprintf("This is a test email for %s.\n\nYour agent is set up and ready to receive emails.", agent.EmailAddress()) |
| 1236 | |
| 1237 | // A platform test is a normal outbound send through the same screening: |
| 1238 | // block ⇒ refuse, review ⇒ hold, flag ⇒ send + annotate. |
| 1239 | testReq := outbound.SendRequest{To: to, Subject: subject, Body: body} |
| 1240 | verdict := a.screenOutbound(ctx, agent, testReq) |
| 1241 | if verdict.Block() { |
| 1242 | a.auditRowless(ctx, agent, blockAuditID(agent.ID, testReq), testReq, verdict) |
| 1243 | a.emitBlockedOutbound(agent, blockAuditID(agent.ID, testReq), testReq, verdict) |
| 1244 | return nil, &OutboundError{http.StatusForbidden, "blocked_by_policy", "test message blocked by outbound policy"} |
| 1245 | } |
| 1246 | if verdict.Review() { |
| 1247 | msg, err := a.HoldForApprovalCore(ctx, agent, testReq, "test", "") |
| 1248 | if err != nil { |
| 1249 | return nil, &OutboundError{http.StatusInternalServerError, "internal_error", "failed to hold message for approval"} |
| 1250 | } |
| 1251 | if verdict.Annotate() { |
| 1252 | a.annotateAndAudit(ctx, agent, msg.ID, testReq, verdict) |
| 1253 | } |
| 1254 | return &OutboundResult{Held: true, PendingMessageID: msg.ID, ApprovalExpiresAt: msg.ApprovalExpiresAt}, nil |
| 1255 | } |
| 1256 | |
| 1257 | message, err := outbound.ComposeMessage(headerFrom, to, nil, subject, body, "text/plain", "", nil, a.fromDomain, "", "") |
| 1258 | if err != nil { |
| 1259 | log.Printf("[api] compose test email failed: %v", err) |
| 1260 | return nil, &OutboundError{http.StatusInternalServerError, "internal_error", "failed to compose test email"} |
| 1261 | } |
| 1262 | messageID, err := a.smtpRelay.Send(envelopeFrom, to, message) |
| 1263 | if err != nil { |
| 1264 | log.Printf("[api] send test email failed: %v", err) |
| 1265 | return nil, &OutboundError{http.StatusInternalServerError, "internal_error", fmt.Sprintf("failed to send test email: %v", err)} |
| 1266 | } |
| 1267 | log.Printf("[api] test email sent to %s (message_id=%s)", agent.EmailAddress(), messageID) |
| 1268 | // flag verdict: the test send persists no message row, so audit row-less. |
| 1269 | if verdict.Annotate() { |
| 1270 | a.auditRowless(ctx, agent, blockAuditID(agent.ID, testReq), testReq, verdict) |
| 1271 | } |
| 1272 | return &OutboundResult{MessageID: messageID, Method: "smtp"}, nil |
| 1273 | } |
| 1274 | |
| 1275 | // --- Send Email --- |
| 1276 |
nothing calls this directly
no test coverage detected