Compare commits
2 Commits
42644cc0c8
...
bbf75783e7
Author | SHA1 | Date |
---|---|---|
Urko. | bbf75783e7 | |
Urko. | c004e66643 |
|
@ -0,0 +1,65 @@
|
||||||
|
# Mail Sender
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
`mail-sender` is a simple Go library designed to send emails with optional attachments. It's built on top of the standard Go `net/smtp` library with additional support for sending HTML emails and handling multiple attachments.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Send HTML emails.
|
||||||
|
- Attach multiple files to the email.
|
||||||
|
- Built-in support for TLS encryption.
|
||||||
|
- Simple API for sending emails.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Clone this repository:
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://gitea.urkob.com/urko/mail-sender.git
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Here's a basic example on how to use the `mail-sender`:
|
||||||
|
|
||||||
|
1. **Initialize the Email Service**
|
||||||
|
|
||||||
|
```go
|
||||||
|
config := email.MailServiceConfig{
|
||||||
|
Auth: smtp.PlainAuth("", "your@email.com", "your-password", "smtp.youremail.com"),
|
||||||
|
Host: "smtp.youremail.com",
|
||||||
|
Port: "587",
|
||||||
|
From: "your@email.com",
|
||||||
|
}
|
||||||
|
mailService := email.NewMailService(config)
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Send an Email with an Attachment**
|
||||||
|
|
||||||
|
```go
|
||||||
|
emailData := email.EmailMessage{
|
||||||
|
To: "receiver@email.com",
|
||||||
|
Subject: "Test Email",
|
||||||
|
Body: "<h1>Hello!</h1><p>This is a test email.</p>",
|
||||||
|
Attachments: []email.EmailAttachment{
|
||||||
|
{
|
||||||
|
File: attachmentFile, // This is an io.Reader
|
||||||
|
Title: "document.pdf",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := mailService.SendEmail(emailData)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
- Go's standard `net/smtp` package
|
||||||
|
- Go's standard `crypto/tls` package for secure email sending.
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
Feel free to submit issues or pull requests if you find any bugs or have suggestions for improvements.
|
Loading…
Reference in New Issue