string
myemail
=
TextBox1.Text;
string euser = TextBox2.Text;
string pass = TextBox3.Text;
string emailTo = TextBox4.Text;
string title = TextBox5.Text;
string semail = RadioButtonList1.SelectedValue.ToString();
string smtp = TextBox6.Text;
if (semail == " 1 " )
{
MailMessage mailMsg = new MailMessage();
//设置正文格式
mailMsg.BodyFormat = MailFormat.Html;
//设置收件人的邮件地址
mailMsg.To = emailTo;
//设置发送者的邮件地址
mailMsg.From = myemail;
//设置邮件主题
mailMsg.Subject = title;
//设置邮件内容
mailMsg.Body = "test";
//设置支持服务器验证
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置用户名
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", euser);
//设置用户密码
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pass);
try
{
//设置发送邮件服务器
SmtpMail.SmtpServer =smtp;
//发送邮件
SmtpMail.Send(mailMsg);
Response.Write("<script>alert('System.Web.Mail方法发信成功,请注意查收!');</script>");
}
catch (Exception err)
{
Response.Write("System.Web.Mail方法发信失败!" + err.Message.ToString());
}
}
else
{
jmail.Message Jmail = new jmail.Message();
DateTime t = DateTime.Now;
String Subject = title;
String body = "test";
String FromEmail = myemail;
String ToEmail = emailTo;
//Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
Jmail.Silent = true;
//Jmail创建的日志,前提loging属性设置为true
Jmail.Logging = true;
//字符集,缺省为"US-ASCII"
Jmail.Charset = "GB2312";
//信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
Jmail.ContentType = "text/html";
//添加收件人
Jmail.AddRecipient(ToEmail, "", "");
Jmail.From = FromEmail;
//发件人邮件用户名
Jmail.MailServerUserName = euser;
//发件人邮件密码
Jmail.MailServerPassWord = pass;
//设置邮件标题
Jmail.Subject = Subject;
//邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
//Jmail.AddAttachment("c:\\test.jpg", true, null);
//邮件内容
Jmail.Body = "test";
//Jmail发送的方法
Jmail.Send(smtp, false);
Jmail.Close();
if (Jmail.Send(smtp, false) == true)
{
Response.Write("<script>alert('Jmail方法发信成功,请注意查收!');</script>");
}
else
{
Response.Write("<script>alert('Jmail方法发信失败!');</script>");
}
}
string euser = TextBox2.Text;
string pass = TextBox3.Text;
string emailTo = TextBox4.Text;
string title = TextBox5.Text;
string semail = RadioButtonList1.SelectedValue.ToString();
string smtp = TextBox6.Text;
if (semail == " 1 " )
{
MailMessage mailMsg = new MailMessage();
//设置正文格式
mailMsg.BodyFormat = MailFormat.Html;
//设置收件人的邮件地址
mailMsg.To = emailTo;
//设置发送者的邮件地址
mailMsg.From = myemail;
//设置邮件主题
mailMsg.Subject = title;
//设置邮件内容
mailMsg.Body = "test";
//设置支持服务器验证
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置用户名
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", euser);
//设置用户密码
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pass);
try
{
//设置发送邮件服务器
SmtpMail.SmtpServer =smtp;
//发送邮件
SmtpMail.Send(mailMsg);
Response.Write("<script>alert('System.Web.Mail方法发信成功,请注意查收!');</script>");
}
catch (Exception err)
{
Response.Write("System.Web.Mail方法发信失败!" + err.Message.ToString());
}
}
else
{
jmail.Message Jmail = new jmail.Message();
DateTime t = DateTime.Now;
String Subject = title;
String body = "test";
String FromEmail = myemail;
String ToEmail = emailTo;
//Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
Jmail.Silent = true;
//Jmail创建的日志,前提loging属性设置为true
Jmail.Logging = true;
//字符集,缺省为"US-ASCII"
Jmail.Charset = "GB2312";
//信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
Jmail.ContentType = "text/html";
//添加收件人
Jmail.AddRecipient(ToEmail, "", "");
Jmail.From = FromEmail;
//发件人邮件用户名
Jmail.MailServerUserName = euser;
//发件人邮件密码
Jmail.MailServerPassWord = pass;
//设置邮件标题
Jmail.Subject = Subject;
//邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
//Jmail.AddAttachment("c:\\test.jpg", true, null);
//邮件内容
Jmail.Body = "test";
//Jmail发送的方法
Jmail.Send(smtp, false);
Jmail.Close();
if (Jmail.Send(smtp, false) == true)
{
Response.Write("<script>alert('Jmail方法发信成功,请注意查收!');</script>");
}
else
{
Response.Write("<script>alert('Jmail方法发信失败!');</script>");
}
}