删除多余的内容
This commit is contained in:
parent
d3689a7839
commit
e7b4fd4bab
21
mian.go
21
mian.go
|
|
@ -46,20 +46,17 @@ func decodeHeader(header string) (string, error) {
|
|||
}
|
||||
|
||||
func postMailContent(url string, key string, mailContent *MailContent) error {
|
||||
// 将邮件内容转换为 JSON
|
||||
jsonData, err := json.Marshal(mailContent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 创建 HTTP 请求
|
||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// 发送 HTTP 请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
|
@ -67,7 +64,6 @@ func postMailContent(url string, key string, mailContent *MailContent) error {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 读取响应体(如果需要)
|
||||
body, err := io.ReadAll(io.Reader(resp.Body))
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -80,33 +76,21 @@ func postMailContent(url string, key string, mailContent *MailContent) error {
|
|||
|
||||
func mailHandler(origin net.Addr, from string, to []string, data []byte) error {
|
||||
reader := bytes.NewReader(data)
|
||||
// msg, _ := mail.ReadMessage(reader)
|
||||
// subject := msg.Header.Get("Subject")
|
||||
// decodedSubject, _ := decodeHeader(subject)
|
||||
env, _ := enmime.ReadEnvelope(reader)
|
||||
|
||||
subject := env.GetHeader("Subject")
|
||||
// The plain text body is available as mime.Text.
|
||||
fmt.Printf("Text Body: %v chars\n", len(env.Text))
|
||||
|
||||
// The HTML body is stored in mime.HTML.
|
||||
fmt.Printf("HTML Body: %v chars\n", len(env.HTML))
|
||||
// 获取邮件正文
|
||||
// contentType := msg.Header.Get("Content-Type")
|
||||
// mediaType, params, err := mime.ParseMediaType(contentType)
|
||||
|
||||
body := env.HTML
|
||||
if len(body) == 0 {
|
||||
body = env.Text
|
||||
}
|
||||
|
||||
fmt.Println("Body:", body)
|
||||
log.Printf("Received mail from %s for %s with subject %s", from, to[0], subject)
|
||||
|
||||
log.Printf("Received mail from %s for %s with subject %s body %s", from, to[0], subject, body)
|
||||
receivedAt := time.Now()
|
||||
|
||||
receivedAt := time.Now() // 例如,使用当前时间作为接收时间
|
||||
|
||||
// 创建 MailContent 对象
|
||||
mailContent := &MailContent{
|
||||
Key: appConfig.ApiKey,
|
||||
From: from,
|
||||
|
|
@ -118,7 +102,6 @@ func mailHandler(origin net.Addr, from string, to []string, data []byte) error {
|
|||
ReceivedAt: receivedAt.Format(time.RFC3339),
|
||||
}
|
||||
|
||||
// 将邮件内容发送到 API
|
||||
err := postMailContent(appConfig.ApiUrl, appConfig.ApiKey, mailContent)
|
||||
if err != nil {
|
||||
log.Println("Failed to post mail content:", err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user