如何使用C#发送邮件? [英] how to send mail using C#?
本文介绍了如何使用C#发送邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将邮件发送到任何电子邮件地址,该怎么做使用C#。我工作的本地主机上。
解决方案
System.Net.Mail.MailMessage消息=新System.Net.Mail.MailMessage(
新的MailAddress(EmailUsername),新的MailAddress(toemailaddress));message.Subject =邮件主题; //例如:我的新的电子邮件
message.Body =邮件正文; //例:这是我的新的电子邮件......亲切的问候,我
对于SMTP的一部分,你也可以使用 SmtpClient
:
SmtpClient客户端=新SmtpClient(SERVERIP);
client.Credentials =新System.Net.NetworkCredential(EmailUsername,EmailPassword);
client.Send(消息);
请考虑接受一些答案。 0%的接受的幅度不是很大。
编辑,以修复愚蠢的错误。提供我的权利不先检查code。
i want to send mail to any email address, how to do that using C#. i am working on local host.
解决方案
System.Net.Mail.MailMessage message=new System.Net.Mail.MailMessage(
new MailAddress(EmailUsername), new MailAddress("toemailaddress"));
message.Subject = "Message Subject"; // E.g: My New Email
message.Body = "Message Body"; // E.g: This is my new email ... Kind Regards, Me
For the SMTP part, you can also use SmtpClient
:
SmtpClient client = new SmtpClient(ServerIP);
client.Credentials = new System.Net.NetworkCredential(EmailUsername, EmailPassword);
client.Send(message);
Please consider accepting some answers. A 0% accepted rate is not great.
Edited to fix the silly mistakes. Serves me right for not checking the code first.
这篇关于如何使用C#发送邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文