如上图,通过.net代码给发送邮件,在邮件内容中显示发件人昵称,可使用以下代码:
//创建smtpclient对象 System.Net.Mail.SmtpClient client = new SmtpClient(); client.Host = "smtp.163.com";//163的smtp服务器是 smtp.163.com string from = "***@163.com"; string pwd = "密码"; string toMail = "***@qq.com"; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(from, pwd); client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Text.Encoding encoding = System.Text.Encoding.UTF8; string senderDisplayName = "惠鲜蔬果";//这个配置的是发件人的要显示在邮件的名称 string recipientsDisplayName = "昊云";//这个配置的是收件人的要显示在邮件的名称 MailAddress mailfrom = new MailAddress(from, senderDisplayName, encoding);//发件人邮箱地址,名称,编码UTF8 MailAddress mailto = new MailAddress(toMail, recipientsDisplayName, encoding);//收件人邮箱地址,名称,编码UTF8 //创建mailMessage对象 System.Net.Mail.MailMessage message = new MailMessage(mailfrom, mailto); message.Subject = "测试邮件标题"; //正文默认格式为html message.Body = "测试邮件内容"; message.IsBodyHtml = true; message.BodyEncoding = encoding; message.SubjectEncoding = encoding; message.HeadersEncoding = encoding; client.Send(message);