SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["mail"]);//配置邮件服务器
邮件服务器是公司内的服务器,现在程序已经可以发送到公司的内部油箱,
现在想让它可以发送邮件到内部和外部的油箱,请问怎么做?
邮件服务器是公司内的服务器,现在程序已经可以发送到公司的内部油箱,
现在想让它可以发送邮件到内部和外部的油箱,请问怎么做?
mail.From = "[email protected]";
mail.To = mailTo;
mail.Subject = mailSubject;
mail.Body = mailMessage;
mail.BodyEncoding = Encoding.Default;
mail.BodyFormat = MailFormat.Html;
mail.Priority = MailPriority.High; mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "temp"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "temp"); //set your password here
SmtpMail.SmtpServer = "mail.xxx.com.cn"; //your real server goes here //SmtpMail.Send( mail );
在 System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
在 System.Net.Mail.SmtpClient.Send(MailMessage message)
System.Collections.ListDictionaryInternalStackTrace = " 在 System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)\r\n 在 System.Net.Mail.SmtpClient.Send(MailMessage message)\r\n 在
_exceptionMethod = {System.Net.Mail.MailWriter SendMail(System.Net.Mail.MailAddress, System.Net.Mail.MailAddressCollection, System.String, System.Net.Mail.SmtpFailedRecipientException ByRef)}
private void Send(string fromAddress, string fromName, string receiverAddress, string emailSubjet, string emailBody)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From = new System.Net.Mail.MailAddress(fromAddress, fromName);
mail.To.Clear();
// 添加群发列表
string[] receivers = receiverAddress.Split(new char[] { ';' });
foreach (string receiver in receivers)
{
mail.To.Add(new System.Net.Mail.MailAddress(receiver));
}
mail.IsBodyHtml = true;
mail.Subject = emailSubjet;
mail.Body = emailBody;
mail.Priority = System.Net.Mail.MailPriority.High; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = ConfigHelper.GetConfig("SMTPServer");
smtp.Credentials = new System.Net.NetworkCredential(ConfigHelper.GetConfig("SMTPServerUser"), ConfigHelper.GetConfig("SMTPServerPassword"));
smtp.Send(mail);
}
-----------------
这个提示好像是说[email protected]邮箱有问题吧,试试其他的邮箱(比如gmail)。
-----------------
这个提示好像是说[email protected]邮箱有问题吧,试试其他的邮箱(比如gmail)。
油箱是有的!
MailAddress to = new MailAddress("[email protected]", "163");
MailMessage message = new MailMessage(from, to);
message.Subject = "死了";
message.Body = @"人生自古谁无死!.";
MailAddress bcc = new MailAddress("[email protected]");
message.Bcc.Add(bcc); SmtpClient client = new SmtpClient("smtp.163.com");// new SmtpClient(server);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 25;
client.Credentials = new System.Net.NetworkCredential("帐号", "密码"); Console.WriteLine("Sending an e-mail message to {0} and {1}.", to.DisplayName, message.Bcc.ToString());
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
ex.ToString());
}
测试,已经可以使用