mirror of
https://github.com/ivabus/pop
synced 2024-12-04 22:15:08 +03:00
commit
1e4802c7f1
3 changed files with 19 additions and 4 deletions
|
@ -42,12 +42,13 @@ You can grab one from: https://resend.com/api-keys.
|
||||||
|
|
||||||
### Environment
|
### Environment
|
||||||
|
|
||||||
To avoid typing your `From: ` email address, you can also set the `RESEND_FROM`
|
To avoid typing your `From: ` email address, you can also set the `POP_FROM`
|
||||||
environment to pre-fill the field anytime you launch `pop`.
|
environment to pre-fill the field anytime you launch `pop`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export RESEND_API_KEY=$(pass RESEND_API_KEY)
|
export RESEND_API_KEY=$(pass RESEND_API_KEY)
|
||||||
export RESEND_FROM=pop@charm.sh
|
export POP_FROM=pop@charm.sh
|
||||||
|
export POP_SIGNATURE="Sent with [Pop](https://github.com/charmbracelet/pop)!"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
13
main.go
13
main.go
|
@ -12,7 +12,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const RESEND_API_KEY = "RESEND_API_KEY"
|
const RESEND_API_KEY = "RESEND_API_KEY"
|
||||||
const RESEND_FROM = "RESEND_FROM"
|
const POP_FROM = "POP_FROM"
|
||||||
|
const POP_SIGNATURE = "POP_SIGNATURE"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
from string
|
from string
|
||||||
|
@ -21,6 +22,7 @@ var (
|
||||||
body string
|
body string
|
||||||
attachments []string
|
attachments []string
|
||||||
preview bool
|
preview bool
|
||||||
|
signature string
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
@ -42,6 +44,10 @@ var rootCmd = &cobra.Command{
|
||||||
body = string(b)
|
body = string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if signature != "" {
|
||||||
|
body += "\n\n" + signature
|
||||||
|
}
|
||||||
|
|
||||||
if len(to) > 0 && from != "" && subject != "" && body != "" && !preview {
|
if len(to) > 0 && from != "" && subject != "" && body != "" && !preview {
|
||||||
err := sendEmail(to, from, subject, body, attachments)
|
err := sendEmail(to, from, subject, body, attachments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -85,9 +91,12 @@ func init() {
|
||||||
rootCmd.Flags().StringSliceVarP(&attachments, "attach", "a", []string{}, "Email's attachments")
|
rootCmd.Flags().StringSliceVarP(&attachments, "attach", "a", []string{}, "Email's attachments")
|
||||||
rootCmd.Flags().StringSliceVarP(&to, "to", "t", []string{}, "Recipients")
|
rootCmd.Flags().StringSliceVarP(&to, "to", "t", []string{}, "Recipients")
|
||||||
rootCmd.Flags().StringVarP(&body, "body", "b", "", "Email's contents")
|
rootCmd.Flags().StringVarP(&body, "body", "b", "", "Email's contents")
|
||||||
rootCmd.Flags().StringVarP(&from, "from", "f", os.Getenv(RESEND_FROM), "Email's sender "+commentStyle.Render("($RESEND_FROM)"))
|
envFrom := os.Getenv(POP_FROM)
|
||||||
|
rootCmd.Flags().StringVarP(&from, "from", "f", envFrom, "Email's sender "+commentStyle.Render("($"+POP_FROM+")"))
|
||||||
rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject")
|
rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject")
|
||||||
rootCmd.Flags().BoolVarP(&preview, "preview", "p", false, "Whether to preview the email before sending")
|
rootCmd.Flags().BoolVarP(&preview, "preview", "p", false, "Whether to preview the email before sending")
|
||||||
|
envSignature := os.Getenv("POP_SIGNATURE")
|
||||||
|
rootCmd.Flags().StringVarP(&signature, "signature", "x", envSignature, "Signature to display at the end of the email. "+commentStyle.Render("($"+POP_SIGNATURE+")"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
5
model.go
5
model.go
|
@ -101,6 +101,11 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
||||||
body.Cursor.Style = cursorStyle
|
body.Cursor.Style = cursorStyle
|
||||||
body.CharLimit = 4000
|
body.CharLimit = 4000
|
||||||
body.SetValue(defaults.Text)
|
body.SetValue(defaults.Text)
|
||||||
|
|
||||||
|
// Adjust for signature (if none, this is a no-op)
|
||||||
|
body.CursorUp()
|
||||||
|
body.CursorUp()
|
||||||
|
|
||||||
body.Blur()
|
body.Blur()
|
||||||
|
|
||||||
// Decide which input to focus.
|
// Decide which input to focus.
|
||||||
|
|
Loading…
Reference in a new issue