【Vegas原创】Jmail发送邮件(Vegas Final版)2007年10月22日UPDATE:正文中图片的显示
1.asp:
set mail=CreateObject("jmail.Message")
mail.Charset ="gb2312"
mail.From ="**" 'from
mail.FromName="【Summary Daily Report】"
mail.AddRecipient "**" 'to
mail.AddRecipient "**@**" 'to
mail.subject=Subject
mail.HTMLBody= strBody
mail.AddAttachment(path)
On Error Resume Next
mail.Send("MailServer")
mail.close()
set mail=nothing
response.write date &"发送成功"
mail.Charset ="gb2312"
mail.From ="**" 'from
mail.FromName="【Summary Daily Report】"
mail.AddRecipient "**" 'to
mail.AddRecipient "**@**" 'to
mail.subject=Subject
mail.HTMLBody= strBody
mail.AddAttachment(path)
On Error Resume Next
mail.Send("MailServer")
mail.close()
set mail=nothing
response.write date &"发送成功"
经典实例:
<%
Session("ConnectionString")="Provider=SQLOLEDB;User id=sa;Password=***;Initial Catalog=***;Data Source=10.*.*.*"
set Connection = Server.CreateObject ("ADODB.Connection")
Connection.Open Session("ConnectionString")
strA="select name from members where account_id='"+Request.QueryString("Account_ID")+"'"
set rsA=connection.Execute(strA)
FromName=trim(rsA("name"))
'邮件正文
strsql="select txt,Filename,File_Name from bbs where unique_id="+Request.QueryString("Unique_ID")
'response.write strsql
'response.end
set rs=connection.execute(strsql)
Body=trim(rs("txt"))
Name1=trim(rs("Filename"))
Name2=trim(rs("File_Name"))
'全公司
strCom="select distinct mail from members where mail is not null"
'strCom="select mail from members where mail is not null and account_id in ('vegas lee','sarah ding')"
set rsAll=connection.Execute(strCom)
do while not rsall.eof
strCompony = strCompony + rsAll("mail")+";"
rsAll.movenext
loop
set mail=CreateObject("jmail.Message")
mail.Charset ="gb2312"
mail.From = "*@*"
mail.Subject =Request.QueryString("title")
mail.FromName=FromName +"发出了【全公司公告】,详请看邮件正文。"
if not isnull(name2) then
path=server.MapPath("Object\BBS") & "\" &name2
mail.AddAttachment (path)
end if
dim aEmail
aEmail = split(strCompony,";")
for i=0 to UBound(aEmail)-1
mail.AddRecipient Replace(aEmail(i)," ","")
next
mail.HTMLBody=Body
'On Error Resume Next
mail.Send("*****")
mail.close()
set mail=nothing
response.redirect("bbs.asp")
%>
Session("ConnectionString")="Provider=SQLOLEDB;User id=sa;Password=***;Initial Catalog=***;Data Source=10.*.*.*"
set Connection = Server.CreateObject ("ADODB.Connection")
Connection.Open Session("ConnectionString")
strA="select name from members where account_id='"+Request.QueryString("Account_ID")+"'"
set rsA=connection.Execute(strA)
FromName=trim(rsA("name"))
'邮件正文
strsql="select txt,Filename,File_Name from bbs where unique_id="+Request.QueryString("Unique_ID")
'response.write strsql
'response.end
set rs=connection.execute(strsql)
Body=trim(rs("txt"))
Name1=trim(rs("Filename"))
Name2=trim(rs("File_Name"))
'全公司
strCom="select distinct mail from members where mail is not null"
'strCom="select mail from members where mail is not null and account_id in ('vegas lee','sarah ding')"
set rsAll=connection.Execute(strCom)
do while not rsall.eof
strCompony = strCompony + rsAll("mail")+";"
rsAll.movenext
loop
set mail=CreateObject("jmail.Message")
mail.Charset ="gb2312"
mail.From = "*@*"
mail.Subject =Request.QueryString("title")
mail.FromName=FromName +"发出了【全公司公告】,详请看邮件正文。"
if not isnull(name2) then
path=server.MapPath("Object\BBS") & "\" &name2
mail.AddAttachment (path)
end if
dim aEmail
aEmail = split(strCompony,";")
for i=0 to UBound(aEmail)-1
mail.AddRecipient Replace(aEmail(i)," ","")
next
mail.HTMLBody=Body
'On Error Resume Next
mail.Send("*****")
mail.close()
set mail=nothing
response.redirect("bbs.asp")
%>
PS:Jmail注册:
regsvr32 %path%/jmail.dll
2..net版:
2.1 vb.net版:
Sub sendmail()
Dim jm As New jmail.Message
Dim chkOK As Boolean = False
Dim strServerName As String
jm.Charset = "gb2312"
jm.ContentType = "text/html"
jm.From = "**@***.com"
jm.FromName = "DTS TRAINING"
jm.Subject = "开课通知"
jm.AddRecipientCC(strRece, strReceive)
jm.AddRecipientCC("@", "Aki Young")
jm.AddRecipientBCC(" @", "Cici Wang")
body += "</table></body></html>"
Dim strFile As String
Dim appFile As String
jm.Body = body
If jm.Send("*****") Then
chkOK = True
Else
chkOK = False
End If
If chkOK = True Then
lblmsg.Text = "发送成功!"
End If
jm.Close()
jm = Nothing
End Sub
Dim jm As New jmail.Message
Dim chkOK As Boolean = False
Dim strServerName As String
jm.Charset = "gb2312"
jm.ContentType = "text/html"
jm.From = "**@***.com"
jm.FromName = "DTS TRAINING"
jm.Subject = "开课通知"
jm.AddRecipientCC(strRece, strReceive)
jm.AddRecipientCC("@", "Aki Young")
jm.AddRecipientBCC(" @", "Cici Wang")
body += "</table></body></html>"
Dim strFile As String
Dim appFile As String
jm.Body = body
If jm.Send("*****") Then
chkOK = True
Else
chkOK = False
End If
If chkOK = True Then
lblmsg.Text = "发送成功!"
End If
jm.Close()
jm = Nothing
End Sub
c#版:
private void Button1_Click(object sender, System.EventArgs e)
{
jmail.Message jmessage=new jmail.MessageClass();
jmessage.Charset="GB2312";
jmessage.From = "*@*.com";
jmessage.FromName= "Vegas" ;
jmessage.Subject="test email from jmessage";
jmessage.AddRecipient("*@*.com","Vegas","123");
jmessage.Body= "Vegas is a tallent!";
jmessage.Send("***",false);
Response.Write ("<script language=javascript>alert('email sent successfully!')</script>");
jmessage.Close() ;
}
{
jmail.Message jmessage=new jmail.MessageClass();
jmessage.Charset="GB2312";
jmessage.From = "*@*.com";
jmessage.FromName= "Vegas" ;
jmessage.Subject="test email from jmessage";
jmessage.AddRecipient("*@*.com","Vegas","123");
jmessage.Body= "Vegas is a tallent!";
jmessage.Send("***",false);
Response.Write ("<script language=javascript>alert('email sent successfully!')</script>");
jmessage.Close() ;
}
2007年10月22日UPDATE:正文中图片的显示:
public int SendJmail(string title,string strText,string strPICDir,string strFromSender, string tmpRecipients, string tmpRecipientCCs, string tmpRecipientBCCs)
{
int SendedMailCnt = 0;
jmail.Message MesMail = new jmail.Message();
strFromSender = "";
//图片的关键
string daxondir = @"\\sc00-vegas\pg\daxon.bmp";
string strAttIDdaxon= MesMail.AddAttachment(daxondir, true, "");
string strDaxon=string.Format("cid:{0}", strAttIDdaxon);
string strGreeting = "<p class=MsoNormal><font size=4 face='Monotype Corsiva'><span lang=EN-US style='font-size:15.0pt;font-family:Monotype Corsiva'>Dear sir,<o:p></o:p></span></font></p>";
string strBye = "..."
strBye = strBye + ""
//string strPICURL = "http://localhost/MESReport/Report/SampleChartInquiry.aspx?datefm=Yesterday&dateto=Yesterday&defect=3K&staname=Packing&shift=%&size=%&glue=%&line=%&lot=%&emp=%&zero=N&type=0&seq=18";
string strMailServer="";
MesMail.Charset = "GB2312";
MesMail.Subject = title;
MesMail.ISOEncodeHeaders = true;
MesMail.From = strFromSender;
if (tmpRecipients.ToString().Trim() != "")
{
string[] strRecipients = tmpRecipients.Split(';');
foreach (string Recipient in strRecipients)
{
string Rec = Recipient.Replace(" ", "") + "@";
MesMail.AddRecipient(Rec, "", "");
}
}
MesMail.AppendHTML("<head><style type=text/css media=all>.form_title { font-family: Verdana;font-size: 12px;font-weight: bolder;color: #333333;}.form_content { font-family: Verdana; font-size: 12px; color: #333333; font-weight: bolder;</style></head><body lang=ZH-CN link=blue vlink=purple>");
MesMail.AppendHTML(strGreeting);
string strPhoto="";
// IF have Photo 另一个图片:)
if (strPICDir.Trim() != "")
{
if (strPICDir.Trim() == "1")
{
DateTime Today = DateTime.Now;
string strToday = Today.AddDays(-1).ToString("M.d.yyyy-M.d.yyyy");
strPICDir = @"\\10.91.50.27\Report\dayreport_(" + strToday + @")\Web 使用Web 用户排名.gif";
}
string strAttID = MesMail.AddAttachment(strPICDir,false,"");
strPhoto = string.Format("<img src=\"cid:{0}\" border=0><br>", strAttID);
}
//strPICURL = SetDateTime(strPICURL);
//tmpMail.AddURLAttachment(strPICURL, string.Format("Web{0}.html", 0), false, "yes");
MesMail.AppendHTML(strText);
MesMail.AppendHTML("<br>");
//string strPageName = "SampleChartInquiry.aspx";
//MesMail.AppendHTML(FormatHTMLTable(GetTableData(strPICURL, strPageName)));
MesMail.AppendHTML(strPhoto);
MesMail.AppendHTML("<br><br></body></html>");
MesMail.AppendHTML(strBye);
MesMail.Send(strMailServer,false );
MesMail.Attachments.Clear();
MesMail.Clear();
MesMail = null;
return SendedMailCnt;
}
{
int SendedMailCnt = 0;
jmail.Message MesMail = new jmail.Message();
strFromSender = "";
//图片的关键
string daxondir = @"\\sc00-vegas\pg\daxon.bmp";
string strAttIDdaxon= MesMail.AddAttachment(daxondir, true, "");
string strDaxon=string.Format("cid:{0}", strAttIDdaxon);
string strGreeting = "<p class=MsoNormal><font size=4 face='Monotype Corsiva'><span lang=EN-US style='font-size:15.0pt;font-family:Monotype Corsiva'>Dear sir,<o:p></o:p></span></font></p>";
string strBye = "..."
strBye = strBye + ""
//string strPICURL = "http://localhost/MESReport/Report/SampleChartInquiry.aspx?datefm=Yesterday&dateto=Yesterday&defect=3K&staname=Packing&shift=%&size=%&glue=%&line=%&lot=%&emp=%&zero=N&type=0&seq=18";
string strMailServer="";
MesMail.Charset = "GB2312";
MesMail.Subject = title;
MesMail.ISOEncodeHeaders = true;
MesMail.From = strFromSender;
if (tmpRecipients.ToString().Trim() != "")
{
string[] strRecipients = tmpRecipients.Split(';');
foreach (string Recipient in strRecipients)
{
string Rec = Recipient.Replace(" ", "") + "@";
MesMail.AddRecipient(Rec, "", "");
}
}
MesMail.AppendHTML("<head><style type=text/css media=all>.form_title { font-family: Verdana;font-size: 12px;font-weight: bolder;color: #333333;}.form_content { font-family: Verdana; font-size: 12px; color: #333333; font-weight: bolder;</style></head><body lang=ZH-CN link=blue vlink=purple>");
MesMail.AppendHTML(strGreeting);
string strPhoto="";
// IF have Photo 另一个图片:)
if (strPICDir.Trim() != "")
{
if (strPICDir.Trim() == "1")
{
DateTime Today = DateTime.Now;
string strToday = Today.AddDays(-1).ToString("M.d.yyyy-M.d.yyyy");
strPICDir = @"\\10.91.50.27\Report\dayreport_(" + strToday + @")\Web 使用Web 用户排名.gif";
}
string strAttID = MesMail.AddAttachment(strPICDir,false,"");
strPhoto = string.Format("<img src=\"cid:{0}\" border=0><br>", strAttID);
}
//strPICURL = SetDateTime(strPICURL);
//tmpMail.AddURLAttachment(strPICURL, string.Format("Web{0}.html", 0), false, "yes");
MesMail.AppendHTML(strText);
MesMail.AppendHTML("<br>");
//string strPageName = "SampleChartInquiry.aspx";
//MesMail.AppendHTML(FormatHTMLTable(GetTableData(strPICURL, strPageName)));
MesMail.AppendHTML(strPhoto);
MesMail.AppendHTML("<br><br></body></html>");
MesMail.AppendHTML(strBye);
MesMail.Send(strMailServer,false );
MesMail.Attachments.Clear();
MesMail.Clear();
MesMail = null;
return SendedMailCnt;
}
喜欢请赞赏一下啦^_^