用C#写web应用程序的 发送邮件功能。前端和后端的代码都要(aspx和aspx.cs文件都要) 15
展开全部
public class SendEmail
{
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="t">收件人邮件地址</param>
/// <param name="f">发件人邮件地址</param>
/// <param name="subject">邮件主题</param>
/// <param name="body">邮件内容</param>
/// <param name="username">登录smtp主机时用到的用户名,注</param>
/// <param name="password">登录smtp主机时用到的用户密码</param>
/// <param name="smtpHost">发送邮件用到的smtp主机</param>
public void Send(string t, string f, string subject, string body, string userName, string password, string smtpHost,int port)
{
try
{
MailAddress f1 = new MailAddress(f);
MailAddress t1 = new MailAddress(t);
MailMessage message = new MailMessage(f1, t1);
message.Subject = subject;//设置邮件主题
message.IsBodyHtml = true;//设置邮件正文为html格式
message.Body = body;//设置邮件内容
SmtpClient client = new SmtpClient(smtpHost, port);
client.Credentials = new NetworkCredential(userName, password);
client.Send(message);
}
catch (Exception ex)
{
}
}
}
username看情况,用不同的邮箱会不一样,不过要么就是XXX,要么就是XXX@XX.com,两者都试试就行
{
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="t">收件人邮件地址</param>
/// <param name="f">发件人邮件地址</param>
/// <param name="subject">邮件主题</param>
/// <param name="body">邮件内容</param>
/// <param name="username">登录smtp主机时用到的用户名,注</param>
/// <param name="password">登录smtp主机时用到的用户密码</param>
/// <param name="smtpHost">发送邮件用到的smtp主机</param>
public void Send(string t, string f, string subject, string body, string userName, string password, string smtpHost,int port)
{
try
{
MailAddress f1 = new MailAddress(f);
MailAddress t1 = new MailAddress(t);
MailMessage message = new MailMessage(f1, t1);
message.Subject = subject;//设置邮件主题
message.IsBodyHtml = true;//设置邮件正文为html格式
message.Body = body;//设置邮件内容
SmtpClient client = new SmtpClient(smtpHost, port);
client.Credentials = new NetworkCredential(userName, password);
client.Send(message);
}
catch (Exception ex)
{
}
}
}
username看情况,用不同的邮箱会不一样,不过要么就是XXX,要么就是XXX@XX.com,两者都试试就行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询