【发布时间】:2017-01-08 05:35:18
【问题描述】:
我正在使用此代码从雅虎发送电子邮件。
string smtpAddress = "smtp.mail.yahoo.com";
int portNumber = 587;
bool enableSSL = true;
string emailFrom = "mitshel@yahoo.com";
string password = "xxxxxx!";
string emailTo = "dimitris.chris@yahoo.com";
string subject = "Hello";
string body = "Hello, I'm just writing this to say Hi!";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
// Can set to false, if you are sending pure text.
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
但如果我想添加更多电子邮件地址怎么办?我试过这个,但我得到一个错误:
string emailTo = "mitsoshellas@yahoo.com" ,"dimitris.christoforidis@hotmail.com" ;
【问题讨论】:
-
试试这个:
string emailTo = "mitsoshellas@yahoo.com, dimitris.christoforidis@hotmail.com";(所有的电子邮件地址都包含在一个字符串中,在“”内 - 即“”)
标签: c#