Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HELP] How to make senderAddress Dynamic #803

Open
sharukhkhanajm opened this issue Jan 4, 2024 · 0 comments
Open

[HELP] How to make senderAddress Dynamic #803

sharukhkhanajm opened this issue Jan 4, 2024 · 0 comments
Labels
type/bug Something isn't working

Comments

@sharukhkhanajm
Copy link

Code Implement

package types

import (
	"os"

	"github.com/nikoksr/notify"
	awsSes "github.com/nikoksr/notify/service/amazonses"
)

// CustomNotifier holds the notify instance and any services we've set up.
type CustomNotifier struct {
	notifier   *notify.Notify
	sesService *awsSes.AmazonSES
	// ... other services
}

// NewCustomNotifier creates a new CustomNotifier with all services initialized.
func NewCustomNotifier() (*CustomNotifier, error) {
	// Initialize the notify instance
	n := notify.New()
	var senderAddress string 

	// Initialize all services here (like sesService, discordService, etc.)

	// For AWS SES
	sesSvc, err := awsSes.New(
		os.Getenv("AWS_MAIL_ACCESS_KEY"),
		os.Getenv("AWS_MAIL_SECRET_KEY"),
		os.Getenv("AWS_MAIL_REGION"),
		senderAddress,
	)

	if err != nil {
		return nil, err // Handle the error if SES service fails to initialize
	}

	// ... initialize other services

	// Return a new CustomNotifier
	return &CustomNotifier{
		notifier:   n,
		sesService: sesSvc,
		// ... other services
	}, nil
}

// SendWithSES sends a notification via AWS SES.
func (cn *CustomNotifier) SendWithSES(s *FiberServer, receivers, subject, message string) error {
	cn.notifier.UseServices(cn.sesService)
	cn.sesService.AddReceivers(receivers)
	return cn.notifier.Send(s.Ctx, subject, message)
}

How can I make the final parameter, senderAddress, dynamic in this code?

My use case is i may use noreply@"+os.Getenv("DOMAIN_NAME") or support@"+os.Getenv("DOMAIN_NAME")

@sharukhkhanajm sharukhkhanajm added the type/bug Something isn't working label Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant