-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Sendmail command #13079
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
Merged
Merged
Sendmail command #13079
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
016b35b
Add SendSync method
zhiburt 538d0db
Add sendmail command
zhiburt 8ecbcc7
add checks that if either title or content is empty then error out
zhiburt 5c0524a
Add a confirmation step
zhiburt 2abad3e
Add --force option to bypass confirm step
zhiburt 9c98e13
Move implementation of runSendMail to a different file
zhiburt a750b18
Add copyrighting comment
zhiburt 3cb7d18
Make content optional
zhiburt d3723b5
Fix import style
zhiburt 087129c
Merge branch 'master' of https://github.com/go-gitea/gitea into sendm…
zhiburt 2ed24b5
Use batch when getting all users
zhiburt 6f4b38d
Merge branch 'sendmail_command' of github.com:zhiburt/gitea into send…
zhiburt 59a1bee
Send emails one by one instead of as one chunck
zhiburt f5a108d
Send messages concurantly
zhiburt 5b5f8c5
Use SendAsync+Flush instead of SendSync
zhiburt 042c259
Add timeout parameter to sendemail command
zhiburt a25d8be
Fix spelling mistake
zhiburt b350eea
Update cmd/admin.go
zhiburt 3d5b393
Connect to a running Gitea instance
zhiburt cee82ff
Merge branch 'sendmail_command' of github.com:zhiburt/gitea into send…
zhiburt 6968eb9
Fix mispelling
zhiburt af3cff6
Add copyright comment
zhiburt b959bf1
Merge branch 'master' into sendmail_command
lunny 1b9f0ee
Merge branch 'master' into sendmail_command
techknowlogick 490fa03
Merge branch 'master' into sendmail_command
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/services/mailer" | ||
zhiburt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
func runSendMail(c *cli.Context) error { | ||
if err := argsSet(c, "title"); err != nil { | ||
return err | ||
} | ||
|
||
if err := initDB(); err != nil { | ||
return err | ||
} | ||
|
||
subject := c.String("title") | ||
confirmSkiped := c.Bool("force") | ||
body := c.String("content") | ||
timeout := c.Duration("timeout") | ||
|
||
if !confirmSkiped { | ||
if len(body) == 0 { | ||
fmt.Print("warning: Content is empty") | ||
} | ||
|
||
fmt.Print("Proceed with sending email? [Y/n] ") | ||
isConfirmed, err := confirm() | ||
if err != nil { | ||
return err | ||
} else if !isConfirmed { | ||
fmt.Println("The mail was not sent") | ||
return nil | ||
} | ||
} | ||
|
||
var emails []string | ||
err := models.IterateUser(func(user *models.User) error { | ||
emails = append(emails, user.Email) | ||
return nil | ||
}) | ||
if err != nil { | ||
return errors.New("Cann't find users") | ||
} | ||
|
||
fmt.Printf("Sending %d emails", len(emails)) | ||
|
||
mailer.NewContext() | ||
|
||
for _, email := range emails { | ||
msg := mailer.NewMessage([]string{email}, subject, body) | ||
mailer.SendAsync(msg) | ||
} | ||
|
||
err = mailer.FlushMessages(timeout) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.