JMAIL組件沒有安裝?;蜃?。。
創(chuàng)新互聯(lián)建站專注于精河企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),電子商務(wù)商城網(wǎng)站建設(shè)。精河網(wǎng)站建設(shè)公司,為精河等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站建設(shè),專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)
最好下載4.4pro破解版安裝。
或者regsvr32 注冊下 dll文件
Visual Basic 6中發(fā)送郵件的新方法
用VB6編寫發(fā)送郵件的程序,有多種E-mail組件可供選擇,如MAPIMessages、IIS4.0附帶的CDONTS(NTS Collaboration Data Objects)以及許多第三方廠商開發(fā)的Email軟件等。本文介紹用CDONTS開發(fā)VB下的郵件程序方法。
1. 確認(rèn)已安裝SMTP服務(wù)器
首先,必須確認(rèn)在IIS服務(wù)器上已安裝SMTP服務(wù)器,這是安裝Option Pack時被缺省安裝的選項。如果SMTP服務(wù)器已安裝,在System32目錄下會存在一個名為cdonts.dll的文件。
2. 最簡單的郵件發(fā)送程序
以下是一個最簡單的郵件發(fā)送程序,它由me@hotmail.net向abc@263.net發(fā)出一封標(biāo)題為“Title”、內(nèi)容為“Hello”的E-mail:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
ObjMail.Send "me@hotmail.net ", "abc@263.net","Title","Hello"
Set objMail=nothing
End Sub
3. 發(fā)送郵件附件
如果有附加的文件需要隨同郵件傳送,可以使用CDONTS的AttachFile方法:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
With ObjMail
.From= "me@hotmail.net "
.To= "abc@263.net"
.Subject="Title"
.Body="Hello"
.AttachFile "c:\document\ sample.doc","sample.doc"
.Send
End With
Set objMail=nothing
End Sub
4. CDONTS組件常用屬性和方法
CDONTS組件常用的屬性和方法列舉如下:
屬性:
Version:返回CDONTS組件的版本號
MailFormat:郵件格式,1-普通文本類型;0-MIME類型
Cc:設(shè)置一個或多個參閱的郵件地址
From:郵件發(fā)送者的地址
To :郵件接受者的地址
Subject:標(biāo)題
Body:內(nèi)容
BodyFormat:內(nèi)容格式,1-普通文本;0-超文本
方法:
AttachFile:附加一個文件
AttachURL:附加一個地址
Send:發(fā)送郵件
5. 發(fā)送超文本格式的E-mail
你一定見到過許多使用超文本格式的E-mail,其中不但可以有圖片、聲音,甚至還可以嵌入動畫。如果給你的朋友也發(fā)送一封這樣的郵件,一定會帶給他(她)意外的驚喜,因為這用一般的郵件發(fā)送程序是無能為力的。以下使用CDONTS組件發(fā)送一個HTML格式的郵件,其中包含有一幅名為sample.gif的圖片,程序如下:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
Dim strHTML as String
StrHTML=""
StrHTML= StrHTML+""
StrHTML = StrHTML +"
用CDONTS發(fā)送Email的例子"
StrHTML= StrHTML+"
"
StrHTML= StrHTML+"
以上例子嵌入了圖片sample.gif
"
StrHTML= StrHTML+""
With ObjMail
.From= "me@hotmail.net "
.To= "abc@263.net"
.Subject="Title"
.Body=strHTML
.AttachURL "c:\mydata\sample.gif","sample.gif"
.BodyFormat=0
.EmailFormat=0
.Send
End With
Set objMail=nothing
End Sub
到這里,相信大家一定發(fā)現(xiàn)SMTP郵件處理的一個缺陷了。SMTP服務(wù)器接收你的輸出消息,但并不做發(fā)送者名字和地址的驗證,這本是由SMTP的異步發(fā)送機(jī)制所決定的,但有人可能別有用心地用它來假扮別人發(fā)送郵件!本文強(qiáng)烈建議各位切勿輕易試用,一旦讓ISP知道你的行徑,你的帳號極可能會被立即刪除。
在Identity2.0里面封裝了IIdentityMessageService接口,可以用來發(fā)送接收郵件。
看看
Imports System.Threading.Tasks
Imports System.Security.Claims
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin
Imports Microsoft.Owin.Security
public function SendAsync(message as IdentityMessage) as task
dim credentialUserName = "郵箱登錄名"
dim sentFrom = "你的郵箱地址"
dim pwd= "郵箱登錄密碼";
dim client as new System.Net.Mail.SmtpClient("smtp服務(wù)器地址")
client.Port = 25'mtp郵件服務(wù)器端口
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
client.UseDefaultCredentials = false
dim credentials as new System.Net.NetworkCredential(credentialUserName, pwd)
client.EnableSsl = true
client.Credentials = credentials
dim mail as new System.Net.Mail.MailMessage(sentFrom, message.Destination)
mail.Subject = message.Subject
mail.Body = message.Body
return client.SendMailAsync(mail)
end function
我只有ACCESS的VBA代碼供你參考,vba與vb很多代碼是可以共用的,你不妨參與研究下:
ACCESS發(fā)送郵件代碼
access 2009-02-11 16:41 閱讀23 評論0 字號: 大大 中中 小小 Private Sub Command1_Click() '發(fā)送郵件,依據(jù)ACCESS開發(fā)答疑200問P226頁
'首先,確保已經(jīng)安裝了OutLook,然后在引用中引用Microsoft OutLook對象,在輸入以下代碼就可實現(xiàn)創(chuàng)建一個新郵件,并添加一個附件到郵件中,然后發(fā)送郵件的功能。
'通過引用OutLook.Application對象,Access可以循環(huán)OutLook對象里面的所有內(nèi)容,例如可以讀取OutLook里的所有郵件、聯(lián)系人、約會、日記等信息,還可修改OutLook內(nèi)置的“規(guī)則精靈”
'的內(nèi)容。
Dim myOlApp As Object
Dim myNamespace As Object
Set myOlApp = CreateObject("OutLook.Application") '創(chuàng)建OutLook應(yīng)用程序?qū)ο?/p>
Set myNamespace = myOlApp.getNamespace("MAPI") '獲取MAPI命名空間
Set myFolder = myNamespace.getDefaultFolder(6) '獲取默認(rèn)的文件夾
Set myitem = myOlApp.CreateItem(0) '創(chuàng)建新郵件
myitem.Display
Set myRecipient = myitem.Recipients.Add("rcylbx@21cn.com") '為郵件添加收件人
myRecipient.Type = 1
myitem.Subject = "test" '設(shè)置郵件主題
MsgBox "ok"
myitem.Attachments.Add ("d:\test.txt") '添加郵件附件,注意確保硬盤下有這個文件
myitem.Save
myitem.Send
MsgBox "ok"
End Sub
Private Sub Command2_Click()
'代碼說明:
'本代碼可以在安裝了outlook(2000以上版本的)的機(jī)器上運(yùn)行。不過outlook xp 以上
'的版本由于出于防止郵件病毒的目的,對發(fā)送郵件進(jìn)行監(jiān)控,運(yùn)用本程序每發(fā)送一封
'email都需要用戶確認(rèn),會有點麻煩,但是還是出于安全的角度考慮。
'可以將這段代碼嵌入access的模塊?excel的宏中運(yùn)行?
'程序要求:
'需要引用 "microsoft outlook x.x library"
'代碼:
Dim olkapp As Outlook.Application '在使用outlook之前必須先聲明outlook應(yīng)用程序的對象,應(yīng)用程序
Dim newmail As MailItem '在使用outlook之前必須先聲明outlook應(yīng)用程序的對象,郵件項目對象
Dim emailadd, para As String
Set olkapp = CreateObject("outlook.application") '指定outlook應(yīng)用程序的實體變量
Set newmail = olkapp.CreateItem(olMailItem) '指定郵件項目的實體變量
'郵件正文內(nèi)容
para = para + "祝新春快樂,并友情提醒注意新的郵件病毒。"
'收件人的email地址,這里沒有輸入內(nèi)容。
emailadd = "rcylbx@21cn.com"
With newmail
.To = emailadd '發(fā)送郵件地址
.Subject = "新春快樂" ' 郵件的主題
.Importance = olImportanceHigh '郵件的為重要等級
.Body = para '將郵件正文內(nèi)容指定para變量內(nèi)容
'.Send '發(fā)送
.Display '啟動視窗
End With
On Error GoTo continue
SendEmail:
newmail.Display
DoEvents
SendKeys "%s", Wait:=True
DoEvents
AppActivate newmail
GoTo SendEmail '發(fā)送不成功誓不罷休
continue:
On Error GoTo 0
Set olkapp = Nothing
Set newmail = Nothing
End Sub
Sub email_send()
Dim olkapp As Outlook.Application
Dim newmail As MailItem
Dim emailadd, para As String
Set olkapp = CreateObject("outlook.application")
Set newmail = olkapp.CreateItem(olMailItem)
'郵件正文內(nèi)容
para = para + "祝新春快樂,并友情提醒注意新的郵件病毒。"
'收件人的email地址,這里沒有輸入內(nèi)容。
emailadd = ""
With newmail
.To = emailadd
.Subject = "新春快樂" ' 郵件的主題
.Importance = olImportanceHigh '郵件的為重要等級
.Body = para '將郵件正文內(nèi)容指定para變量內(nèi)容
.Send '發(fā)送
End With
End Sub
Private Sub Command3_Click()
'方法一是用代碼模擬發(fā)送郵件確認(rèn) (代碼引用論壇前輩的代碼)
Dim objOL As Object
Dim itmNewMail As Object
'引用Microsoft Outlook 物件模型
Set objOL = CreateObject("Outlook.Application")
Set itmNewMail = objOL.CreateItem(olMailItem)
With itmNewMail
.Subject = "chijanzen Mail Test" '主旨
.Body = "發(fā)送郵件測試2222" '本文
.To = "rcylbx@21cnl.com" '收件者
.Attachments.Add "d:\test.txt", olByValue, 1, "4th Quarter 1996 Results Chart"
.Display '啟動視窗
End With
On Error GoTo continue
SendEmail:
AppActivate itmNewMail
DoEvents
SendKeys "%s", Wait:=True
DoEvents
AppActivate itmNewMail
GoTo SendEmail '發(fā)送不成功誓不罷休
continue:
On Error GoTo 0
Set objOL = Nothing
Set itmNewMail = Nothing
'再次測試中發(fā)現(xiàn),窗口標(biāo)題為中文時,AppActivate命令不能執(zhí)行。將AppActivate命令改為Display方法,可解決此問題,即將AppActivate itmNewMail改為itmNewMail.display。
End Sub
'方法一是用代碼模擬發(fā)送郵件確認(rèn) (代碼引用論壇前輩的代碼)
Sub SendMail()
Dim objOL As Object
Dim itmNewMail As Object
'引用Microsoft Outlook 物件模型
Set objOL = CreateObject("Outlook.Application")
Set itmNewMail = objOL.CreateItem(olMailItem)
With itmNewMail
.Subject = "chijanzen Mail Test" '主旨
.Body = Application.UserName "發(fā)送郵件測試2222" '本文
.To = "171262953@qq.com" '收件者
.Attachments.Add "C:\PDOS.DEF", olByValue, 1, "4th Quarter 1996 Results Chart"
.Display '啟動視窗
End With
On Error GoTo continue
SendEmail:
AppActivate itmNewMail
DoEvents
SendKeys "%s", Wait:=True
DoEvents
AppActivate itmNewMail
GoTo SendEmail '發(fā)送不成功誓不罷休
continue:
On Error GoTo 0
Set objOL = Nothing
Set itmNewMail = Nothing
End Sub
'再次測試中發(fā)現(xiàn),窗口標(biāo)題為中文時,AppActivate命令不能執(zhí)行。將AppActivate命令改為Display方法,可解決此問題,即將AppActivate itmNewMail改為itmNewMail.display。
**************************************
***************************************
Sub Send_Order_Mail()
Dim cnn As ADODB.Connection
Dim rst_cusid, rst_order_list As ADODB.Recordset
Dim olkapp As Outlook.Application
Dim newmail As MailItem
Set olkapp = CreateObject("outlook.application")
Set cnn = New ADODB.Connection
cnn.Open CurrentProject.Connection
Set rst_cusid = New ADODB.Recordset
rst_cusid.Open "select distinct CustomerID,CompanyName,Email from v_order_list", cnn, adOpenKeyset, adLockReadOnly
If rst_cusid.RecordCount 1 Then Exit Sub
Set rst_order_list = New ADODB.Recordset
For i = 1 To rst_cusid.RecordCount
rst_order_list.Open "select * from v_order_list where CustomerID = " + "'" + rst_cusid.Fields(0) + "'", cnn, adOpenKeyset, adLockReadOnly
With rst_order_list
para = "Dear " + .Fields(1) + ":" + Chr(10)
para = para + Space(3) + "Your Company " + .Fields(0) + " has Order those Good:" + Chr(10)
For j = 1 To .RecordCount
para = para + Space(3) + "Good Name :" + .Fields(2) + " Order Date :" + CStr(.Fields(3)) + " Price:" + CStr(.Fields(4)) + Chr(10)
Next
End With
rst_order_list.Close
para = para + Space(30) + "Yours Loadhigh" 'para為信件內(nèi)容
Set newmail = olkapp.CreateItem(olMailItem)
With newmail
.To = rst_cusid.Fields(2) '接收郵件的信箱
.Subject = rst_cusid.Fields(1) + " Order List" '信件標(biāo)題
.Body = para
.Send '發(fā)送
End With
rst_cusid.MoveNext
para = ""
Next
rst_cusid.Close
Set rst_cusid = Nothing
Set rst_order_list = Nothing
cnn.Close
Set cnn = Nothing
End Sub
***********************************************************
Function test1()
Dim objMail As MailItem
Dim objAttachments As Attachment
Dim App As New Outlook.Application
Set objMail = App.CreateItem(olMailItem)
objMail.Save
Set objAttachments = objMail.Attachments.Add("c:\temp\a.xls", olByValue, 1, "a.xls")
With objMail
.To = "chenge@shtip.com.cn" '接收郵件的信箱
.Subject = "test" '信件標(biāo)題
.Body = "test"
.Send '發(fā)送
End With
'objMail.Display
End Function
*********************************************************
VBScript code
Set Msg =
CreateObject("CDO.Message")
With Msg
.To = "someone@microsoft.com"
.From = "userX@microsoft.com"
.Subject = "Lunch meeting"
.TextBody = "I have attached the suggested menu."
.AddAttachment ""
.Send
End With
另,若因發(fā)垃圾郵件被163.com封賬號,可以聯(lián)系客服解釋是電腦中了病毒。