下的jmail4.3并安装了,看了几个帖子,貌似有的说还要用命令提示符再编译一下,弄成一个新的.dll,到底需不需要~?
用不用改修改webconfig?还有什么需要的配置?
小妹第一次开发项目,请各位赐教~~!!
书上找的代码如下:
protected void btSend_Click(object sender, EventArgs e)
{
try
{
sendEmail(txtSender.Text.Trim(), txtSUser.Text.Trim(), txtEUser.Text.Trim(), txtEPwd.Text.Trim(), txtReceiver.Text.Trim(), txtSubject.Text.Trim(), txtContent.Text.Trim(), txtEServer.Text.Trim());
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
} }
public void sendEmail(string sender, string senderuser, string euser, string epwd, string receiver, string subject, string body, string eserver)
{
jmail.MessageClass jmMessage = new jmail.MessageClass();
jmMessage.Charset = "GB2312";
jmMessage.ISOEncodeHeaders = false;
jmMessage.From = sender;
jmMessage.FromName = senderuser;
jmMessage.Subject = subject;
jmMessage.MailServerUserName = euser;
jmMessage.MailServerPassWord = epwd;
jmMessage.AddRecipient(receiver, "", "");
if (this.upFile.PostedFile.ContentLength != 0)
{
string sFilePath = this.upFile.PostedFile.FileName;
jmMessage.AddAttachment(@sFilePath, true, "");
}
jmMessage.Body = body;
if (jmMessage.Send(eserver, false))
{
Page.RegisterClientScriptBlock("ok", "<script language=javascript>alert('发送成功')</script>");
//this.saveEmail();
}
else
Page.RegisterClientScriptBlock("ok", "<script language=javascript>alert('发送失败')</script>");
jmMessage = null;
}
}
用不用改修改webconfig?还有什么需要的配置?
小妹第一次开发项目,请各位赐教~~!!
书上找的代码如下:
protected void btSend_Click(object sender, EventArgs e)
{
try
{
sendEmail(txtSender.Text.Trim(), txtSUser.Text.Trim(), txtEUser.Text.Trim(), txtEPwd.Text.Trim(), txtReceiver.Text.Trim(), txtSubject.Text.Trim(), txtContent.Text.Trim(), txtEServer.Text.Trim());
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
} }
public void sendEmail(string sender, string senderuser, string euser, string epwd, string receiver, string subject, string body, string eserver)
{
jmail.MessageClass jmMessage = new jmail.MessageClass();
jmMessage.Charset = "GB2312";
jmMessage.ISOEncodeHeaders = false;
jmMessage.From = sender;
jmMessage.FromName = senderuser;
jmMessage.Subject = subject;
jmMessage.MailServerUserName = euser;
jmMessage.MailServerPassWord = epwd;
jmMessage.AddRecipient(receiver, "", "");
if (this.upFile.PostedFile.ContentLength != 0)
{
string sFilePath = this.upFile.PostedFile.FileName;
jmMessage.AddAttachment(@sFilePath, true, "");
}
jmMessage.Body = body;
if (jmMessage.Send(eserver, false))
{
Page.RegisterClientScriptBlock("ok", "<script language=javascript>alert('发送成功')</script>");
//this.saveEmail();
}
else
Page.RegisterClientScriptBlock("ok", "<script language=javascript>alert('发送失败')</script>");
jmMessage = null;
}
}
/// 发送邮件的方法
/// </summary>
/// <param name="toEmail">邮件接收地址</param>
/// <param name="fromEmail">邮件发送地址</param>
/// <param name="subject">邮件主题</param>
/// <param name="body">邮件内容</param>
/// <param name="userName">发送邮件用户名</param>
/// <param name="password">发送邮件密码</param>
/// <param name="smtpHost">smtp服务器</param>
public void SendEmail(string toEmail, string fromEmail, string subject, string body, string userName, string password, string smtpHost)
{
//设置邮件发送对象
MailMessage mailObj = new MailMessage();
// 设置邮件的发送地址
mailObj.From = fromEmail;
//设置邮件的接收地址
mailObj.To = toEmail;
//设置邮件发送的主题
mailObj.Subject = subject;
//设置邮件发送的内容
mailObj.Body = body;
// html格式的邮件
mailObj.BodyFormat = MailFormat.Html;
// 设置为高级优先权
mailObj.Priority = System.Web.Mail.MailPriority.High;
//验证
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName); //用户名
mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //密码
//使用SmtpMail对象发送邮件
SmtpMail.SmtpServer = smtpHost;
SmtpMail.Send(mailObj);
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Mail;namespace MailSender
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
MailMessage objMailMessage;
MailAttachment objMailAttachment; // 创建一个附件对象
objMailAttachment = new MailAttachment("C:\\1.xml");//发送邮件的附件 // 创建邮件消息
objMailMessage = new MailMessage();
objMailMessage.From = "[email protected]";//源邮件地址
objMailMessage.To = "********@qq.com";//目的邮件地址
objMailMessage.Subject = "邮件发送标题:你好";//发送邮件的标题
objMailMessage.Body = "邮件发送标内容:测试一下是否发送成功!";//发送邮件的内容
objMailMessage.Attachments.Add(objMailAttachment);//将附件附加到邮件消息对象中 //接着利用sina的SMTP来发送邮件,需要使用Microsoft .NET Framework SDK v1.1和它以上的版本
//基本权限
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //用户名
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "mytest110"); //密码
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "******"); //如果没有上述三行代码,则出现如下错误提示:服务器拒绝了一个或多个收件人地址。服务器响应为:530 Authentication required //SMTP地址
SmtpMail.SmtpServer = "smtp.sina.com"; // 开始发送邮件
// 在发送之前,去新浪邮箱里开启POP/SMTP设置 邮箱设置->账户->POP/SMTP设置->开启
// 否则会报错误0x80040217. The server response was not available
SmtpMail.Send(objMailMessage);
}
}
}