oci-api 0.6.0

OCI (Oracle Cloud Infrastructure) API client for Rust
Documentation
//! Send a test email to go@gocoder.xyz

use oci_api::client::Oci;
use oci_api::services::email::{Email, EmailAddress, EmailDelivery, Recipients};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load .env file if exists
    let _ = dotenvy::dotenv();

    println!("๐Ÿš€ Sending test email to go@gocoder.xyz...\n");

    // Load configuration
    let oci_client = Oci::from_env()?;
    let tenancy_id = oci_client.tenancy_id().to_string();
    let compartment_id = std::env::var("OCI_COMPARTMENT_ID").unwrap_or_else(|_| tenancy_id.clone());

    // Create clients
    let email_client = EmailDelivery::new(oci_client).await?;

    // Get approved senders
    println!("๐Ÿ“‹ Fetching approved senders...");
    let senders = email_client
        .list_senders(&compartment_id, Some("ACTIVE"), None)
        .await?;

    if senders.is_empty() {
        eprintln!("โŒ No approved senders found!");
        return Ok(());
    }

    let approved_sender = &senders[0];
    println!("โœ‰๏ธ  Using sender: {}\n", approved_sender.email_address);

    // Build email content using builder pattern
    let email = Email::builder()
        .sender(EmailAddress::with_name(
            &approved_sender.email_address,
            "GoCoder Test System",
        ))
        .recipients(Recipients::to(vec![EmailAddress::new("go@gocoder.xyz")]))
        .subject("๐Ÿงช OCI API Rust Client Test Email")
        .body_text(
            "Hello!\n\n\
             This is a test email sent from the OCI API Rust client.\n\n\
             If you're seeing this, it means the email delivery system is working correctly! ๐ŸŽ‰\n\n\
             Best regards,\n\
             GoCoder Test System"
        )
        .body_html(
            r#"
            <!DOCTYPE html>
            <html>
            <head>
                <style>
                    body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
                    .container { max-width: 600px; margin: 0 auto; padding: 20px; }
                    .header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
                              color: white; padding: 30px; border-radius: 10px 10px 0 0; text-align: center; }
                    .content { background: #f9f9f9; padding: 30px; border-radius: 0 0 10px 10px; }
                    .badge { background: #4CAF50; color: white; padding: 5px 10px; 
                             border-radius: 5px; display: inline-block; margin: 10px 0; }
                    .footer { text-align: center; margin-top: 20px; color: #666; font-size: 12px; }
                </style>
            </head>
            <body>
                <div class="container">
                    <div class="header">
                        <h1>๐Ÿงช Test Email</h1>
                        <p>OCI API Rust Client</p>
                    </div>
                    <div class="content">
                        <p>Hello!</p>
                        <div class="badge">โœ… System Test</div>
                        <p>This is a test email sent from the <strong>OCI API Rust client</strong>.</p>
                        <p>If you're seeing this, it means the email delivery system is working correctly! ๐ŸŽ‰</p>
                        <p><strong>Technical Details:</strong></p>
                        <ul>
                            <li>API: OCI Email Delivery Service</li>
                            <li>Client: Rust Implementation</li>
                            <li>Region: ap-chuncheon-1</li>
                            <li>Status: <span style="color: #4CAF50;">โœ“ Operational</span></li>
                        </ul>
                        <p>Best regards,<br>GoCoder Test System</p>
                    </div>
                    <div class="footer">
                        <p>This is an automated test email. Please do not reply.</p>
                    </div>
                </div>
            </body>
            </html>
            "#
        )
        .build()?;

    // Send email
    println!("๐Ÿ“ค Sending email...");
    match email_client.send(email).await {
        Ok(response) => {
            println!("\nโœ… Email sent successfully!");
            println!("๐Ÿ“จ Message ID: {}", response.message_id);
            println!("๐Ÿ“ฎ Envelope ID: {}", response.envelope_id);

            if let Some(suppressed) = response.suppressed_recipients {
                if !suppressed.is_empty() {
                    println!("\nโš ๏ธ  Note: Some recipients were suppressed:");
                    for recipient in suppressed {
                        println!("   - {}", recipient.email);
                    }
                }
            }

            println!("\n๐Ÿ’Œ Check go@gocoder.xyz inbox!");
        }
        Err(e) => {
            eprintln!("\nโŒ Failed to send email: {}", e);
            return Err(e.into());
        }
    }

    Ok(())
}