500分求教vb程序通过SMTP发mail的代码。最好有密码验证的,没有也没关系,只要能发出去就行。分不够,下次转么开贴给分
我们公司的pop3被封了
我查看了MSTOP(陈建华(东莞立晨企业资讯服务有限公司)) 的贴子http://expert.csdn.net/Expert/topic/2844/2844258.xml?temp=.9636499
2. 最简单的邮件发送程序
以下是一个最简单的邮件发送程序,它由[email protected]向[email protected]发出一封标题为“Title”、内容为“Hello”的E-mail:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
ObjMail.Send "[email protected] ", "[email protected]","Title","Hello"
Set objMail=nothing
End Sub
出现的提示:ActiveX 组件无法产生对象,我不知道还要引用什幺我查看了其他的一些代码,好象都是通过pop3发的。
我们公司是用notes发邮件的,可不可以在vb里面调用notes发邮件啊,
各位大哥大姐给个建议吧,万分感谢!
我们公司的pop3被封了
我查看了MSTOP(陈建华(东莞立晨企业资讯服务有限公司)) 的贴子http://expert.csdn.net/Expert/topic/2844/2844258.xml?temp=.9636499
2. 最简单的邮件发送程序
以下是一个最简单的邮件发送程序,它由[email protected]向[email protected]发出一封标题为“Title”、内容为“Hello”的E-mail:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
ObjMail.Send "[email protected] ", "[email protected]","Title","Hello"
Set objMail=nothing
End Sub
出现的提示:ActiveX 组件无法产生对象,我不知道还要引用什幺我查看了其他的一些代码,好象都是通过pop3发的。
我们公司是用notes发邮件的,可不可以在vb里面调用notes发邮件啊,
各位大哥大姐给个建议吧,万分感谢!
是错的,我已经回复过了引用microsoft cdo for nts 1.2 library
通过测试
Private Sub Command1_Click()
Dim objMail As Object
Set objMail = CreateObject("CDONTS.NewMail")
objMail.Send "[email protected] ", "[email protected]", "Title", "Hello"
Set objMail = Nothing
End Sub
我引用了microsoft cdo for nts 1.2 library
怎么还出现 ActiveX 组件无法产生对象 的错误提示啊,请再指点一下,谢谢
各位大哥大姐给个建议吧,万分感谢!用winsock控件或mapi
'Sub Send([From], [To], [Subject], [Body], [Importance])Private Sub Command2_Click()
Dim Mailto As New CDONTS.NewMail
Mailto.Send "[email protected]", "[email protected]", "Title", "Hello"
Set Mailto = Nothing
End Sub
'Sub Send([From], [To], [Subject], [Body], [Importance])Private Sub Command2_Click()
Dim Mailto As New CDONTS.NewMail
Mailto.Send "[email protected]", "[email protected]", "Title", "Hello"
Set Mailto = Nothing
End Sub
前言随着计算机网络的发展,人与人之间信息传输的时间大为缩短。许多文件都是以电子邮件的形式来传送;通常使用过计算机的人,或多或少都会用到E-Mail来传输信息。本文将介绍如何用Microsoft MAPI (Messaging Application Program Interface)来设计Mail程序。首先用Visual Basic所提供的MAPISession control及MAPIMessage control 来设计Mail收发程序,然后用Microsoft Internet Explorer 3.0所提供的E-Mail程序来测试程序设计的正确性MAPI简介MAPI接口是由微软公司提供的一系列供使用者开发Mail、Scheduling、bulletin board、communication程序的编程接口。在使用MAPI设计程序时,首先必须在程序和MAPI之间建立一条或数条Session;当Session建立好之后,Client端程序就可以使用MAPI所提供的功能。MAPI的功能主要分成三大部分:Address Books、Transport和Message Store。Address Books主要负责设置E-mail type、protocol等参数;Transport负责文件的发送和接收等功能;Message Store则负责发送接收等信息的处理。说了这么多,MAPI接口好像很可怕。不过没关系,Visual Basic所提供的MAPISession control及MAPIMessage control,已经将许多复杂的部分包装成简单 的property和功能,我们只需要对property及功能作一些简单的设置,就可以写一个mail发送和接收的程序。以下笔者将用Visual Basic的MAPI
control,来设计mail传送和接收的程序。E-mail发送部分Step 1:设置Exchange各项参数进入Exchange系统,选择新增设置文件;屏幕上会显示所需要的信息服务,选择 Internet Mail。将设置文件的名称设为test。屏幕会显示两个选项,您可以选择以modem方式,或以network方式连接。笔者所用的是Internet专线,所以选择network;假若您是使用 PPP拨号方式连接Internet,就要选择modem。选择network后,Exchange会要求我们输入mail server的IP address。笔者现在所使用的 Mail server地址是202.96.128.111,在本程序中便将它设置为该地址。接着将Transform message的模式设置为automatic,这样当我们连接到Mail server
时,新的信息会自动download到local端。接下来,将您所使用的Email address、full name、password、download path一步
一步设置好,这样就完成了Exchange各项参数的设置。Step 2:程序设计在File选项中选择New
Project建立一个新的工程,这时屏幕上会看到许多选项,例如ActiveX Document.EXE、ActiveX Document.DLL、ActiveX.EXE、ActiveX Control等...,这时要选Standard.EXE。在Project下,选择Property属性选项;在general选项下,将Project Name改为 email-send, 并将Form名称及Caption更改为email-send 。在屏幕的Form上加入一个MAPImessage
control,取名为MAPIm1;加入一个MAPIsession control,取名为MAPIs1;加入三个textbox control,取名为subject、content、addr。并在三个textbox前各加入一个Label,将Caption分别改为subject、content、addr。为方便读者了解彼此关系,以下表解释一遍:
(TextBox)
Name
-----------------------------------------------------
subject(输入信件标题)
content(输入信件内容)
addr(输入信件要传送的位址)(Label)
Caption
-----------------------------------------------
subject(输入信件标题提示)
content(输入信件内容提示)
addr(输入信件要传送的位址提示)将MAPIm1的各项property设置如下:
download mail=TRUE
logoUI= TRUE
newsession=FALSE
username="test"
这里将download mail设置为TRUE,当程序和mail server第一次连接时,会将新的mail download到local端。将logoUI设置为TRUE,则当您程序中logon名称输入错误时,系统会显示一个Message Box来让您输入正确的名称。由于这个程序仅使用到一条session,我们将它的值设置成FALSE。当然啦!如果您有许多session要建立的话,也可以将它设置成TRUE。username中所填的,是我们在Exchange中所新增的设置文件名称;如果没有填内容的话,系统将会显示一些message box请您输入文件。
在屏幕的Form上加入三个Button control,logon、logoff与send,分别将Caption 改为log on、log off、send。(Button)
Name Caption
--------------------------------------------------------
logon(执行登入命令) logon
logoff(执行登出命令) logoff
send(执行传出信件命令) send在 logon_Click()中加入以下程序代码,这个动作是使我们登录到mail server。
MAPIS1.SignOn
MAPIM1.SessionID = MS1.SessionID
MsgBox "your id is" + Str(MS1.SessionID)MS1.SignOn是作登录的动作。在登录时,因为已经将MAPIm1 control的download mail属性设置为TRUE,所以可以在屏幕上看到message box显示系统正在download mail。登录成功后,系统会传回一个sessionID,将该ID填入MAPIM1的SessionID中,这样就可以利用这条session来传送E-mail。在 logoff_Click()中加入以下程序代码,这个动作是使我们离开mail
server。
MAPIS1.SignOff在 send_Click()中加入以下程序代码,这个动作是使我们发送email。
MAPIM1.Compose
MAPIM1.RecipDisplayName = addr.text
MAPIM1.AddressResolveUI = True
MAPIM1.MsgSubject = subject.text
MAPIM1.MsgNoteText = content.text
MAPIM1.Send
MsgBox "you successful"
Compose命令的主要目的,是使您可以改变RecipDisplayName的内容,将所需传送的E-mail地址、主题、文章内容分别填入RecipDisplayName、MsgSubject、MsgNoteText,接着用send命令发送。Step 3:用IE 3.0 Mail程序测试程序
执行上面设计的email-send程序。在subject textbox中填入"发信测试",在address textbox中填入[email protected],在content textbox中输入要传送的内容:"大家好!这是发信测试",接着按传送。这样信件就发送出去了!执行IE 3.0选择接收信件,在mail选项中选择read mail。我们会在inbox中看到一封标题为"发信测试"的信件,接着我们看看它的内容,没错!那就是我们刚寄出的测试信。E-mail接收部分Step 1:程序设计在File选项中选择New Project建立一个新的工程。在屏幕上看到许多选项,如 ActiveX Document.EXE、ActiveX Document.DLL、ActiveX.EXE、ActiveX Control等,这时要选Standard.EXE。接着在Project下,选择Property属性选项;在general选项下,将Project Name改为 email-get,并将FORM名称及Caption更改为 email-get。在屏幕的Form上加入一个MAPImessage control,取名为MAPIm1;加入一个 MAPIsession control,取名为MAPIs1;加入三个Textbox control,分别取名为 subject、content、indexno, 将其Caption改为mail-subject、mail-content、 indexno;并在TextBox前各加入一个Label control,将Caption分别改为subject、 content、indexno。将MAPIm1的各项property设置如下:
download mail=TRUE
logoUI=TRUE
newsession=FALSE
username="test"
这些设置原理如同设计发送mail程序部分。接着,在屏幕的Form上加入一个Button control get-mail,将Caption改为get mail。如同发送mail 程序部分和mail server建立一条session。在 get-mail_Click() 中加入以下程序代码,这个动作是使我们接收email。
MAPIM1.Fetch
Form1.Caption=MAPIM1. MsgCount
MAPIM1.MsgIndex=CINT(indexno.text)
subjec.Text = MM1.MsgNoteText
content.Text = MAPI1.MsgSubject
Fetch命令,是将信件抓到系统存贮器的inbuffer中。我们将信件抓回来后,可以由 MsgCount property知道信件数量。接着可以用MsgIndex设置要看哪一封信件的内容、标题。Stept 2:测试mail接收程序
首先用任何一种mail程序,任意书写几封信到mail server。在Form1的Caption中,我们会看到所接收的信件的数量。 执行上面设计的email-get程序,在indexno textbox中填入1。接着按get mail Button,这样信件内容及标题就会显示在content、subject两个TextBox中。恭喜您成功了!
Option Explicit
Public ServerIp As String 'SMTP服务器地址
Public ServerPort As Long 'SMTP服务器端口Dim strSendName As String '发送人姓名
Dim strReceiveName As String '接收人姓名
Dim strFromMail As String '发送人地址
Dim strToMail As String '接收人地址
Dim m_Date As String '发送日期
Dim strSubject As String '主题
Dim strContent As String '正文
Dim Information As String '从服务器接收响应消息Private Sub cmdSend_Click()
'设置Winsock
Wsock.Close
Wsock.RemoteHost = ServerIp
Wsock.RemotePort = ServerPort
strSendName = txtSName.Text
strReceiveName = txtRName.Text
strFromMail = txtFrom.Text
strToMail = txtTo.Text
m_Date = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
strSubject = txtSubject.Text
strContent = txtContent.Text
Dim mData As String
'构造信件标题字段
mData = "From:" & Chr(32) & strSendName & vbCrLf & _
"Date:" & Chr(32) & m_Date & vbCrLf & _
"X-Mailer: BigAnt Smtp Mailer V1.0" & vbCrLf & _
"To:" & Chr(32) & strReceiveName & vbCrLf & _
"Subject:" & Chr(32) & strSubject & vbCrLf
Wsock.Close
'连接SMTP服务器
Wsock.Connect
If Not WaitForResponse("220", 10) Then
txtMsg.Text = "邮件服务器连接不上......"
Exit Sub
End If
'打开对话
Wsock.SendData "HELO" & " " & Wsock.LocalHostName & vbCrLf
If Not WaitForResponse("250", 10) Then
txtMsg.Text = txtMsg.Text & "无法打开邮件发送对话" & vbCrLf
Exit Sub
End If
'发送发送方地址
Wsock.SendData "MAIL FROM:" & " " & strFromMail & vbCrLf
If Not WaitForResponse("250", 10) Then
txtMsg.Text = txtMsg.Text & "无法发送发送方地址" & vbCrLf
Exit Sub
End If
'发送接收方地址
Wsock.SendData "RCPT TO:" & " " & strToMail & vbCrLf
If Not WaitForResponse("250", 10) Then
txtMsg.Text = txtMsg.Text & "无法发送接收方地址" & vbCrLf
Exit Sub
End If
'发送消息体
Wsock.SendData "DATA" & vbCrLf
If Not WaitForResponse("354", 10) Then
txtMsg.Text = txtMsg.Text & "无法发送消息体" & vbCrLf
Exit Sub
End If
Wsock.SendData mData & vbCrLf
Wsock.SendData strContent & vbCrLf
Wsock.SendData "." & vbCrLf
If Not WaitForResponse("250", 20) Then
txtMsg.Text = txtMsg.Text & "消息体发送不成功" & vbCrLf
Exit Sub
End If
'结束邮件发送对话
Wsock.SendData "QUIT" & vbCrLf
If Not WaitForResponse("221", 10) Then
Exit Sub
End If
Wsock.Close
txtMsg.Text = txtMsg.Text & "邮件发送成功"
txtMsg.Text = txtMsg.Text & mData & vbCrLf & strContent & vbCrLf
End Sub'该按扭事件过程用于设置smtp服务器
Private Sub cmdSetUp_Click()
frmSetup.Show
End Sub'程序加载时读出上次的设置
Private Sub Form_Load()
ServerIp = GetSetting("email", "smtpserver", "serverip", "")
ServerPort = GetSetting("email", "smtpserver", "serverport", 25)
Wsock.Protocol = sckTCPProtocol
End Sub'程序退出时保存设置
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
SaveSetting "email", "smtpserver", "serverip", ServerIp
SaveSetting "email", "smtpserver", "serverport", ServerPort
End Sub'接收服务器的响应消息
Private Sub Wsock_DataArrival(ByVal bytesTotal As Long)
Wsock.GetData Information
txtMsg.Text = txtMsg.Text & Information & vbCrLf
End Sub'该函数用于等待服务器响应码
Private Function WaitForResponse(strResponse As String, WaitTime As Integer) As Boolean
Dim WaitSt As Date
WaitSt = Now()
While InStr(1, Information, strResponse, vbTextCompare) < 1
DoEvents
If DateDiff("s", WaitSt, Now) > WaitTime Then
Information = ""
WaitForResponse = False
Exit Function
End If
Wend
Information = ""
WaitForResponse = True
End Function窗体2(frmsetup)
Option ExplicitPrivate Sub cmdQuit_Click(Index As Integer)
If Index = 0 Then
smtp.ServerIp = txtIp.Text
smtp.ServerPort = CLng(txtPort.Text)
End If
Unload Me
End SubPrivate Sub Form_Load()
txtIp.Text = smtp.ServerIp
txtPort.Text = smtp.ServerPort
End Sub
2. 目录mail-attch包含发送带附件的email的程序。
3. 目录mailchecker包含接收邮件的程序。
4. 目录Mime包含编码(base64,quote-printable,Uuencode)解码的程序。
5. 目录sendmail包含发送无附件的email的程序。
6. 目录vbmail包含使用MAPI发送接收邮件的程序。
可能是cdo组件专用于win2000,winnt吧
引用microsoft cdo for nts 1.2 libraryPrivate Sub Command1_Click()
Dim objMail As Object
Set objMail = CreateObject("CDONTS.NewMail")
objMail.Send "[email protected] ", "[email protected]", "Title", "Hello"
Set objMail = Nothing
End Sub
我引用了 Microsoft CDO For NTS 1.2 Library
Mailto 也创建成功了,可是出现ActiveX 组件无法产生对象 的错误提示
真郁闷!大哥大姐在帮帮忙吧!
http://www.ourfly.com/download/downloadlist.aspx?type=VB
vb网络编程从入门到精通源码 第六章mapi控件的应用
我是这样设置的
SMTP 服务器地址: smtp.163.com
SMTP 服务器端口:25
To: [email protected] From :[email protected]我们公司的pop3被封了,但是 smtp没有被封,
我可以在163 网站上实现 ff2003@163 和hhffyy @ 163.com 互发信息敬请指点一下,谢谢
MSTOP(陈建华(东莞立晨企业资讯服务有限公司)) 等等
现在结贴,可是我发现最近csdn有问题,我的分数一直没有增加,所以只能先散100分,以后再补,请原谅哦