英文:
How to attach a link in the setBody of gomail?
问题
在这段代码中,我正在尝试将value[2]
作为href
链接,这样如果有人点击该标记,就会被重定向到某个页面,但我不确定如何实现。我搜索了解决方案,但没有找到。
func SendEmail(value [3]string) {
mail := gomail.NewMessage()
myEmail := middleware.LoadEnvVariable("EMAIL")
myPassword := middleware.LoadEnvVariable("APP_PASSWORD")
mail.SetHeader("From", myEmail)
mail.SetHeader("To", value[0])
mail.SetHeader("Reply-To", myEmail)
mail.SetHeader("Subject", value[1])
mail.SetBody("text/html", "<href='localhost:4000'>"+value[2]+"</href>")
a := gomail.NewDialer("smtp.gmail.com", 587, myEmail, myPassword)
if err := a.DialAndSend(mail); err != nil {
log.Fatal(err)
}
}
英文:
In this code, I am trying to make the value[2]
as an href
link so that if somebody clicks on the token, it will be redirected to some page but I am not sure how to do it. I searched for the solution but didn't find it.
func SendEmail(value [3]string) {
mail := gomail.NewMessage()
myEmail := middleware.LoadEnvVariable("EMAIL")
myPassword := middleware.LoadEnvVariable("APP_PASSWORD")
mail.SetHeader("From", myEmail)
mail.SetHeader("To", value[0])
mail.SetHeader("Reply-To", myEmail)
mail.SetHeader("Subject", value[1])
mail.SetBody("text/html", "<href='localhost:4000'>"+value[2]+"</href>")
a := gomail.NewDialer("smtp.gmail.com", 587, myEmail, myPassword)
if err := a.DialAndSend(mail); err != nil {
log.Fatal(err)
}
}
答案1
得分: 1
根据gomail文档,尝试使用<a>
标签:
mail.SetBody("text/html", "<a href=\"" + value[2] + "\">some text</a>")
英文:
Following on the gomail docs, try to use the <a>
tag:
mail.SetBody("text/html", "<a href=\"" + value[2] + "\">some text</a>")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论