2 回答
TA贡献1804条经验 获得超7个赞
我试过在我的机器上运行邮件猪。这是代码{
MailMessage mail = new MailMessage();
mail.To.Add("glitson@gmail.com");
mail.From = new MailAddress("priyesh@gmail.com");
mail.Subject = "Email using Gmail";
string Body = "Hello";
mail.Body = Body;
SmtpClient smtp = new SmtpClient();
smtp.Host = "Localhost"; //Or Your SMTP Server Address
smtp.Port = 1025;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential
("username", "password");
//Or your Smtp Email ID and Password
//smtp.EnableSsl = true;
smtp.Send(mail);
}
TA贡献1860条经验 获得超9个赞
我建议您使用我的库Gomail:
package main
import "gopkg.in/gomail.v2"
func main() {
m := gomail.NewMessage()
m.SetHeader("From", "from@example.com")
m.SetHeader("To", "to@example.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/plain", "What's up?")
d := gomail.NewPlainDialer("smtp.example.com", 587, "user", "123456")
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}
- 2 回答
- 0 关注
- 219 浏览
添加回答
举报