v2.4.6
1、优化初始化设置时的操作说明 2、发件人和发件时间修复 3、发件空指针异常修复
This commit is contained in:
parent
89c24884f2
commit
7a3d056e77
@ -86,6 +86,7 @@ var lang = {
|
|||||||
"move":"Move to group",
|
"move":"Move to group",
|
||||||
"del_rule_confirm":"Are you sure to delete this?",
|
"del_rule_confirm":"Are you sure to delete this?",
|
||||||
"rule_params":"Executed params",
|
"rule_params":"Executed params",
|
||||||
|
"autoSSLWarn":"PMail is not currently running on port 80. If you want PMail to manage SSL certificates automatically, please forward the /.well-known/* route to PMail. See https://github.com/Jinnrry/PMail/issues/94 for details."
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -178,6 +179,7 @@ var zhCN = {
|
|||||||
"move":"移动分组",
|
"move":"移动分组",
|
||||||
"del_rule_confirm":"确定要删除吗?",
|
"del_rule_confirm":"确定要删除吗?",
|
||||||
"rule_params":"执行参数",
|
"rule_params":"执行参数",
|
||||||
|
"autoSSLWarn":"PMail当前未使用80端口启动,如果想要PMail自动管理SSL证书,请将/.well-known/*路由转发到PMail。 详见https://github.com/Jinnrry/PMail/issues/94"
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (navigator.language) {
|
switch (navigator.language) {
|
||||||
|
|||||||
@ -95,8 +95,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div v-if="active == 4" class="ctn_s">
|
<div v-if="active == 4" class="ctn_s">
|
||||||
|
|
||||||
<div class="desc">
|
<div class="desc">
|
||||||
<h2>{{ lang.setDNS }}</h2>
|
<h2>{{ lang.setDNS }}</h2>
|
||||||
<div style="margin-top: 10px;">{{ lang.dns_desc }}</div>
|
<div style="margin-top: 10px;">{{ lang.dns_desc }}</div>
|
||||||
@ -121,6 +121,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<el-alert :closable="false" title="Warning!" type="error" center v-if="active == 5 && sslSettings.type == 0 && port != 80 "
|
||||||
|
:description="lang.autoSSLWarn"
|
||||||
|
/>
|
||||||
|
|
||||||
<div v-if="active == 5" class="ctn">
|
<div v-if="active == 5" class="ctn">
|
||||||
<div class="desc">
|
<div class="desc">
|
||||||
<h2>{{ lang.setSSL }}</h2>
|
<h2>{{ lang.setSSL }}</h2>
|
||||||
@ -142,9 +146,11 @@
|
|||||||
<el-form-item :label="lang.ssl_crt_path" v-if="sslSettings.type == '1'">
|
<el-form-item :label="lang.ssl_crt_path" v-if="sslSettings.type == '1'">
|
||||||
<el-input placeholder="./config/ssl/public.crt" v-model="sslSettings.crt_path"></el-input>
|
<el-input placeholder="./config/ssl/public.crt" v-model="sslSettings.crt_path"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-button v-loading.fullscreen.lock="fullscreenLoading" id="next" style="margin-top: 12px" @click="next">{{
|
<el-button v-loading.fullscreen.lock="fullscreenLoading" id="next" style="margin-top: 12px" @click="next">{{
|
||||||
@ -192,6 +198,8 @@ const fullscreenLoading = ref(false)
|
|||||||
const dnsInfos = ref([
|
const dnsInfos = ref([
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const port = ref(80)
|
||||||
|
|
||||||
const setPassword = () => {
|
const setPassword = () => {
|
||||||
if (adminSettings.hadSeted) {
|
if (adminSettings.hadSeted) {
|
||||||
active.value++;
|
active.value++;
|
||||||
@ -279,7 +287,8 @@ const getSSLConfig = () => {
|
|||||||
if (res.errorNo != 0) {
|
if (res.errorNo != 0) {
|
||||||
ElMessage.error(res.errorMsg)
|
ElMessage.error(res.errorMsg)
|
||||||
} else {
|
} else {
|
||||||
sslSettings.type = res.data
|
sslSettings.type = res.data.type
|
||||||
|
port.value = res.data.port
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -368,6 +377,5 @@ const next = () => {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#next {}
|
#next {}
|
||||||
</style>
|
</style>
|
||||||
@ -33,6 +33,15 @@ type Config struct {
|
|||||||
WebPushToken string `json:"webPushToken"`
|
WebPushToken string `json:"webPushToken"`
|
||||||
Tables map[string]string `json:"-"`
|
Tables map[string]string `json:"-"`
|
||||||
TablesInitData map[string]string `json:"-"`
|
TablesInitData map[string]string `json:"-"`
|
||||||
|
setupPort int // 初始化阶段端口
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) GetSetupPort() int {
|
||||||
|
return c.setupPort
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) SetSetupPort(setupPort int) {
|
||||||
|
c.setupPort = setupPort
|
||||||
}
|
}
|
||||||
|
|
||||||
const DBTypeMySQL = "mysql"
|
const DBTypeMySQL = "mysql"
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package email
|
package email
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cast"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"pmail/config"
|
"pmail/config"
|
||||||
@ -13,6 +15,7 @@ import (
|
|||||||
"pmail/hooks"
|
"pmail/hooks"
|
||||||
"pmail/hooks/framework"
|
"pmail/hooks/framework"
|
||||||
"pmail/i18n"
|
"pmail/i18n"
|
||||||
|
"pmail/models"
|
||||||
"pmail/utils/async"
|
"pmail/utils/async"
|
||||||
"pmail/utils/context"
|
"pmail/utils/context"
|
||||||
"pmail/utils/send"
|
"pmail/utils/send"
|
||||||
@ -107,6 +110,18 @@ func Send(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
|||||||
Name: reqData.From.Name,
|
Name: reqData.From.Name,
|
||||||
EmailAddress: reqData.From.Email,
|
EmailAddress: reqData.From.Email,
|
||||||
}
|
}
|
||||||
|
if reqData.Sender.Email != "" {
|
||||||
|
e.Sender = &parsemail.User{
|
||||||
|
Name: reqData.Sender.Name,
|
||||||
|
EmailAddress: reqData.Sender.Email,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
e.Sender = &parsemail.User{
|
||||||
|
Name: reqData.From.Name,
|
||||||
|
EmailAddress: reqData.From.Email,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
e.Text = []byte(reqData.Text)
|
e.Text = []byte(reqData.Text)
|
||||||
e.HTML = []byte(reqData.HTML)
|
e.HTML = []byte(reqData.HTML)
|
||||||
e.Subject = reqData.Subject
|
e.Subject = reqData.Subject
|
||||||
@ -138,36 +153,36 @@ func Send(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
log.WithContext(ctx).Debugf("插件执行--SendBefore End")
|
log.WithContext(ctx).Debugf("插件执行--SendBefore End")
|
||||||
|
|
||||||
// 邮件落库
|
modelEmail := models.Email{
|
||||||
sql := "INSERT INTO email (type,subject, reply_to, from_name, from_address, `to`, bcc, cc, text, html, sender, attachments,spf_check, dkim_check, create_time,send_user_id,error) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
Type: 1,
|
||||||
sqlRes, sqlerr := db.Instance.Exec(db.WithContext(ctx, sql),
|
Subject: e.Subject,
|
||||||
1,
|
ReplyTo: json2string(e.ReplyTo),
|
||||||
e.Subject,
|
FromName: e.From.Name,
|
||||||
json2string(e.ReplyTo),
|
FromAddress: e.From.EmailAddress,
|
||||||
e.From.Name,
|
To: json2string(e.To),
|
||||||
e.From.EmailAddress,
|
Bcc: json2string(e.Bcc),
|
||||||
json2string(e.To),
|
Cc: json2string(e.Cc),
|
||||||
json2string(e.Bcc),
|
Text: sql.NullString{String: string(e.Text), Valid: true},
|
||||||
json2string(e.Cc),
|
Html: sql.NullString{String: string(e.HTML), Valid: true},
|
||||||
e.Text,
|
Sender: json2string(e.Sender),
|
||||||
e.HTML,
|
Attachments: json2string(e.Attachments),
|
||||||
json2string(e.Sender),
|
SPFCheck: 1,
|
||||||
json2string(e.Attachments),
|
DKIMCheck: 1,
|
||||||
1,
|
SendUserID: ctx.UserID,
|
||||||
1,
|
SendDate: time.Now(),
|
||||||
time.Now(),
|
Status: 1,
|
||||||
ctx.UserID,
|
CreateTime: time.Now(),
|
||||||
"",
|
}
|
||||||
)
|
|
||||||
emailId, _ := sqlRes.LastInsertId()
|
|
||||||
|
|
||||||
if sqlerr != nil || emailId <= 0 {
|
_, err = db.Instance.Insert(&modelEmail)
|
||||||
|
|
||||||
|
if err != nil || modelEmail.Id <= 0 {
|
||||||
log.Println("mysql insert error:", err.Error())
|
log.Println("mysql insert error:", err.Error())
|
||||||
response.NewErrorResponse(response.ServerError, i18n.GetText(ctx.Lang, "send_fail"), err.Error()).FPrint(w)
|
response.NewErrorResponse(response.ServerError, i18n.GetText(ctx.Lang, "send_fail"), err.Error()).FPrint(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
e.MessageId = emailId
|
e.MessageId = cast.ToInt64(modelEmail.Id)
|
||||||
|
|
||||||
async.New(ctx).Process(func(p any) {
|
async.New(ctx).Process(func(p any) {
|
||||||
errMsg := ""
|
errMsg := ""
|
||||||
@ -189,12 +204,12 @@ func Send(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg = err.Error()
|
errMsg = err.Error()
|
||||||
_, err := db.Instance.Exec(db.WithContext(ctx, "update email set status =2 ,error=? where id = ? "), errMsg, emailId)
|
_, err := db.Instance.Exec(db.WithContext(ctx, "update email set status =2 ,error=? where id = ? "), errMsg, modelEmail.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithContext(ctx).Errorf("sql Error :%+v", err)
|
log.WithContext(ctx).Errorf("sql Error :%+v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_, err := db.Instance.Exec(db.WithContext(ctx, "update email set status =1 where id = ? "), emailId)
|
_, err := db.Instance.Exec(db.WithContext(ctx, "update email set status =1 where id = ? "), modelEmail.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithContext(ctx).Errorf("sql Error :%+v", err)
|
log.WithContext(ctx).Errorf("sql Error :%+v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,11 @@ func AcmeChallenge(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type sslResponse struct {
|
||||||
|
Port int `json:"port"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||||
reqBytes, err := io.ReadAll(req.Body)
|
reqBytes, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -121,7 +126,11 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
if reqData["step"] == "ssl" && reqData["action"] == "get" {
|
if reqData["step"] == "ssl" && reqData["action"] == "get" {
|
||||||
sslType := ssl.GetSSL()
|
sslType := ssl.GetSSL()
|
||||||
response.NewSuccessResponse(sslType).FPrint(w)
|
res := sslResponse{
|
||||||
|
Type: sslType,
|
||||||
|
Port: config.Instance.GetSetupPort(),
|
||||||
|
}
|
||||||
|
response.NewSuccessResponse(res).FPrint(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,12 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"pmail/config"
|
||||||
"pmail/controllers"
|
"pmail/controllers"
|
||||||
|
"pmail/utils/ip"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ip string
|
|
||||||
|
|
||||||
// 项目初始化引导用的服务,初始化引导结束后即退出
|
// 项目初始化引导用的服务,初始化引导结束后即退出
|
||||||
var setupServer *http.Server
|
var setupServer *http.Server
|
||||||
|
|
||||||
@ -29,7 +29,14 @@ func SetupStart() {
|
|||||||
HttpPort := 80
|
HttpPort := 80
|
||||||
flag.IntVar(&HttpPort, "p", 80, "初始化阶段Http服务端口")
|
flag.IntVar(&HttpPort, "p", 80, "初始化阶段Http服务端口")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
config.Instance.SetSetupPort(HttpPort)
|
||||||
log.Infof("HttpServer Start On Port :%d", HttpPort)
|
log.Infof("HttpServer Start On Port :%d", HttpPort)
|
||||||
|
if HttpPort == 80 {
|
||||||
|
log.Infof("Please click http://%s to continue.\n", ip.GetIp())
|
||||||
|
} else {
|
||||||
|
log.Infof("Please click http://%s:%d to continue.", ip.GetIp(), HttpPort)
|
||||||
|
}
|
||||||
|
|
||||||
setupServer = &http.Server{
|
setupServer = &http.Server{
|
||||||
Addr: fmt.Sprintf(":%d", HttpPort),
|
Addr: fmt.Sprintf(":%d", HttpPort),
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
|
|||||||
@ -23,7 +23,6 @@ func Init(serverVersion string) {
|
|||||||
if !config.IsInit {
|
if !config.IsInit {
|
||||||
dirInit()
|
dirInit()
|
||||||
|
|
||||||
log.Infof("Please click http://127.0.0.1 to continue.\n")
|
|
||||||
go http_server.SetupStart()
|
go http_server.SetupStart()
|
||||||
<-signal.InitChan
|
<-signal.InitChan
|
||||||
http_server.SetupStop()
|
http_server.SetupStop()
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
package setup
|
package setup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"pmail/i18n"
|
"pmail/i18n"
|
||||||
"pmail/services/auth"
|
"pmail/services/auth"
|
||||||
"pmail/utils/context"
|
"pmail/utils/context"
|
||||||
"pmail/utils/errors"
|
"pmail/utils/errors"
|
||||||
|
"pmail/utils/ip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DNSItem struct {
|
type DNSItem struct {
|
||||||
@ -26,30 +24,11 @@ func GetDNSSettings(ctx *context.Context) ([]*DNSItem, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret := []*DNSItem{
|
ret := []*DNSItem{
|
||||||
{Type: "A", Host: "smtp", Value: getIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
|
{Type: "A", Host: "smtp", Value: ip.GetIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
|
||||||
{Type: "A", Host: "pop", Value: getIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
|
{Type: "A", Host: "pop", Value: ip.GetIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
|
||||||
{Type: "MX", Host: "-", Value: fmt.Sprintf("smtp.%s", configData.Domain), TTL: 3600},
|
{Type: "MX", Host: "-", Value: fmt.Sprintf("smtp.%s", configData.Domain), TTL: 3600},
|
||||||
{Type: "TXT", Host: "-", Value: "v=spf1 a mx ~all", TTL: 3600},
|
{Type: "TXT", Host: "-", Value: "v=spf1 a mx ~all", TTL: 3600},
|
||||||
{Type: "TXT", Host: "default._domainkey", Value: auth.DkimGen(), TTL: 3600},
|
{Type: "TXT", Host: "default._domainkey", Value: auth.DkimGen(), TTL: 3600},
|
||||||
}
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIp() string {
|
|
||||||
resp, err := http.Get("http://ip-api.com/json/?lang=zh-CN ")
|
|
||||||
if err != nil {
|
|
||||||
return "Your Server IP"
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err == nil {
|
|
||||||
var queryRes map[string]string
|
|
||||||
_ = json.Unmarshal(body, &queryRes)
|
|
||||||
|
|
||||||
return queryRes["query"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "Your Server IP"
|
|
||||||
}
|
|
||||||
|
|||||||
32
server/utils/ip/ip.go
Normal file
32
server/utils/ip/ip.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package ip
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ip string
|
||||||
|
|
||||||
|
func GetIp() string {
|
||||||
|
if ip != "" {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.Get("http://ip-api.com/json/?lang=zh-CN ")
|
||||||
|
if err != nil {
|
||||||
|
return "[Your Server IP]"
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err == nil {
|
||||||
|
var queryRes map[string]string
|
||||||
|
_ = json.Unmarshal(body, &queryRes)
|
||||||
|
ip = queryRes["query"]
|
||||||
|
return queryRes["query"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "[Your Server IP]"
|
||||||
|
}
|
||||||
@ -188,7 +188,12 @@ func Send(ctx *context.Context, e *parsemail.Email) (error, map[string]error) {
|
|||||||
|
|
||||||
orgMap := map[string]error{}
|
orgMap := map[string]error{}
|
||||||
errMap.Range(func(key, value any) bool {
|
errMap.Range(func(key, value any) bool {
|
||||||
orgMap[key.(string)] = value.(error)
|
if value != nil {
|
||||||
|
orgMap[key.(string)] = value.(error)
|
||||||
|
}else {
|
||||||
|
orgMap[key.(string)] = nil
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user