网站找了很多,或不全,或者不能发.初学发邮件程序,很多不懂,有哪些要注意的请告之!.net 1.1,VS2003,XP
http://community.csdn.net/Expert/topic/5479/5479627.xml?temp=.2424127
有100分,一起给!
http://community.csdn.net/Expert/topic/5479/5479627.xml?temp=.2424127
有100分,一起给!
//
MailMessage myMail = new MailMessage("发件人", "收件人");
myMail.Subject = TextBox2.Text;
myMail.Body = TextBox3.Text;
myMail.IsBodyHtml = true; //设置SMTP
SmtpClient client = new SmtpClient();
client.Host = "220.181.12.16";
client.Port = 25; client.Credentials = new System.Net.NetworkCredential("用户名", "密码");
client.Send(myMail);
Try
Dim Jmail As New jmail.Message
Dim bRet As Boolean = False
'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(strTo, "", "")
Jmail.From = strFrom
'发件人邮件用户名
Jmail.MailServerUserName = strUserName
'发件人邮件密码
Jmail.MailServerPassWord = strPassword
'设置邮件标题
Jmail.Subject = strSubject
'邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
'Jmail.AddAttachment( "c:\\test.jpg",true,null)
'邮件内容
Jmail.Body = strBody
'Jmail发送的方法
bRet = Jmail.Send(strSmtpServer, False)
If bRet Then
Return True
Else
m_strErr = Jmail.ErrorMessage
Debug.Print(m_strErr)
Return False
End If
Catch ex As Exception
m_strErr = ex.Message
WriteLog(LogType.ErrorLog, "clsMail.SendMailJ", ex.Message)
Return False
End Try End Function
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.Web.Util;
using myJmail;using Tool;
using Manager;
using Entity;public partial class UserControls_Jmaill : System.Web.UI.UserControl
{
string strCurrentPath = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
this.lblTitle.Text = "发送邮件控件";
myJmail.Message Jmail = new myJmail.Message();
DateTime t = DateTime.Now;
String Subject = this.txtTitle.Text;
String body = this.txtContent.Text;
string FromEmail = this.txtFormEmail.Text.Trim();//你的email
String ToEmail = this.txtToEmail.Text;//对方的email
String AddAttachment = this.FileUploadSubject.PostedFile.FileName;
//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";
ToEmail = ToEmail.Replace("\n", "").Replace(" ", "");
string[] str = ToEmail.Split(','); for (int i = 0; i < str.Length; i++)
{
//添加收件人
Jmail.AddRecipient(str[i], "", "");
Jmail.From = FromEmail;
//发件人邮件用户名
Jmail.MailServerUserName = FromEmail;
//发件人邮件密码
Jmail.MailServerPassWord = "";//FromEmail邮箱的登陆密码
//设置邮件标题
Jmail.Subject = Subject;
//邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
Jmail.AddAttachment(AddAttachment, true, null);
//邮件内容
Jmail.Body = body + t.ToString();
//加密文件
//Jmail.PGPEncrypt = true;
//Jmail发送的方法
Jmail.Send("smtp.163.com", false);
Jmail.ClearAttachments();
Jmail.ClearRecipients();
}
Jmail.Close();
}
catch (Exception ex)
{
this.lblMessage.Text = ex.Message;
}
}
}
接分了!!!
是不是com组件注册的路径不一样也不可以.
1.是否安装jmail4.3;
2.端口问题;