如何使用 microsoft c# 通过 smtp 服务器发送电子邮件进行设置
使用 microsoft c# 通过 smtp 服务器发送电子邮件时如何设置“发件人”
如果您查看此图片,您就会明白我的意思
我使用下面的代码发送电子邮件
MailMessage mail = new MailMessage();
mail.To.Add(srUserEmail);
string srBody = "bla bla bla";
mail.From = new MailAddress("[email protected]");
mail.Subject = "bla bla bla";
mail.Body = srBody;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = true;
smtp.Host = "xxx.xx.xx.xx";
smtp.Port = xxx;
smtp.Send(mail);
How to set "from" when sendin email via smtp server with using microsoft c#
if you look this image you will understand what i mean
i use the code below for sending emails
MailMessage mail = new MailMessage();
mail.To.Add(srUserEmail);
string srBody = "bla bla bla";
mail.From = new MailAddress("[email protected]");
mail.Subject = "bla bla bla";
mail.Body = srBody;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = true;
smtp.Host = "xxx.xx.xx.xx";
smtp.Port = xxx;
smtp.Send(mail);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将第二个参数传递给
MailAddress
构造函数:Pass a second argument to the
MailAddress
constructor:像这样设置您的电子邮件地址的格式:
MailAddress 对象应识别
<>
标记内的部分是电子邮件地址,而其前面的部分是发送电子邮件的个人或公司的名称。Format your email address like this:
The MailAddress object should recognize that the part inside
<>
tags is an email address, whereas the part preceding that is the name of the person or business sending the email.