git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/email/console/console.go (about)

     1  package console
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"git.sr.ht/~pingoo/stdx/email"
     8  )
     9  
    10  // Mailer implements the `email.Mailer` interface to print emails to console
    11  type Mailer struct {
    12  }
    13  
    14  // NewMailer returns a new console Mailer
    15  func NewMailer() *Mailer {
    16  	return &Mailer{}
    17  }
    18  
    19  // Send an email using the console mailer
    20  func (mailer *Mailer) SendTransactionnal(ctx context.Context, email email.Email) error {
    21  	data, err := email.Bytes()
    22  	if err != nil {
    23  		return err
    24  	}
    25  	fmt.Println(string(data))
    26  
    27  	return nil
    28  }
    29  
    30  func (mailer *Mailer) SendBroadcast(ctx context.Context, email email.Email) error {
    31  	data, err := email.Bytes()
    32  	if err != nil {
    33  		return err
    34  	}
    35  	fmt.Println(string(data))
    36  
    37  	return nil
    38  }