| 网站首页 | 业界新闻 | 群组 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 179 人关注过本帖
标题:VB6要如何发信
只看楼主 收藏
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:12
帖 子:1668
专家分:3571
注 册:2011-3-24
结帖率:98.67%
  已结贴   问题点数:20  回复次数:7   
VB6要如何发信
电脑内并无安装OUTLOOK或其他邮件软体
是否能单纯使用VB6去寄信件~邮件伺服器使用公司内部的~
在ASP.NET可以寄~但是在VB6不知道怎么写?
2018-06-11 13:14
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:206
帖 子:4184
专家分:25706
注 册:2008-10-15
  得分:20 
1、有一个VB6发信的控件,没用过。
2、这个是使用 网络通讯,你完全可以使用 WINSOCK 自己写一个。
只使用 SMTP 协议就可以完成发信。


授人于鱼,不如授人于渔
早已停用QQ了
2018-06-11 13:50
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:12
帖 子:1668
专家分:3571
注 册:2011-3-24
  得分:0 
CSDN查到这组代码~但是无法运作~
不知道Response是什麼東西老卡在這~
MsgTitle不知道是什麼東西~

程序代码:

Option Explicit

Dim Response As String
Dim Reply As Integer
Dim DateNow As String
Dim first As String, Second As String, Third As String
Dim Fourth As String, Fifth As String, Sixth As String, Ninth As String
Dim Seventh As String, Eighth As String
Dim Start As Single, Tmr As Single

Sub SendEmail(MailServerName As String, FromName As String, FromEmailAddress As String, ToName As String, _
              ToEmailAddress As String, EmailSubject As String, EmailBodyOfMessage As String)

    Winsock1.LocalPort = 0
        
    If Winsock1.State = sckClosed Then
   
        DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
        first = "mail from:" + Chr(32) + FromEmailAddress + vbCrLf
        Second = "rcpt to:" + Chr(32) + ToEmailAddress + vbCrLf
        Third = "Date:" + Chr(32) + DateNow + vbCrLf
        Fourth = "From:" + Chr(32) + FromName + vbCrLf
        Fifth = "To:" + Chr(32) + ToName + vbCrLf
        Sixth = "Subject:" + Chr(32) + EmailSubject + vbCrLf
        Seventh = EmailBodyOfMessage + vbCrLf
        
        Ninth = "X-Mailer: EBT Reporter v 2.x" + vbCrLf  
        Eighth = Fourth + Third + Ninth + Fifth + Sixth  
   
        Winsock1.Protocol = sckTCPProtocol
        Winsock1.RemoteHost = MailServerName
        Winsock1.RemotePort = 25
        Winsock1.Connect
        
        WaitFor ("220")
        
        StatusTxt.Caption = "Connecting...."
        StatusTxt.Refresh
        
        Winsock1.SendData ("HELO worldcomputers.com" + vbCrLf)
   
        WaitFor ("250")
   
        StatusTxt.Caption = "Connected"
        StatusTxt.Refresh
        Winsock1.SendData (first)
        StatusTxt.Caption = "Sending Message"
        StatusTxt.Refresh
   
        WaitFor ("250")
   
        Winsock1.SendData (Second)
   
        WaitFor ("250")
   
        Winsock1.SendData ("data" + vbCrLf)
        
        WaitFor ("354")
        Winsock1.SendData (Eighth + vbCrLf)
        Winsock1.SendData (Seventh + vbCrLf)
        Winsock1.SendData ("." + vbCrLf)
   
        WaitFor ("250")
   
        Winsock1.SendData ("quit" + vbCrLf)
        
        StatusTxt.Caption = "Disconnecting"
        StatusTxt.Refresh
   
        WaitFor ("221")
   
        Winsock1.Close
    Else
        MsgBox (Str(Winsock1.State))
    End If
   
End Sub

Sub WaitFor(ResponseCode As String)
Dim MsgTitle As String
    Start = Timer
    While Len(Response) = 0
        Tmr = Start - Timer
        DoEvents
        If Tmr > 50 Then
            MsgBox "SMTP service error, timed out while waiting for response", 64, MsgTitle
            Exit Sub
        End If
    Wend
    While Left(Response, 3) <> ResponseCode
        DoEvents
        If Tmr > 50 Then
            MsgBox "SMTP service error, impromper response code." _
                & "Code should have been: " + ResponseCode + " Code recieved: " + Response, 64, MsgTitle
            Exit Sub
        End If
    Wend
Response = "" ' Sent response code to blank **IMPORTANT**
End Sub

Private Sub cmdSend_Click()
    SendEmail txtEmailServer.Text, txtFromName.Text, txtFromEmailAddress.Text, txtToName.Text, txtoEmailAddress.Text, txtEmailSubject.Text, txtEmailBodyOfMessage.Text
    'MsgBox ("Mail Sent")
    StatusTxt.Caption = "Mail Sent"
    StatusTxt.Refresh
    Beep
    Close
End Sub

Private Sub cmdExit_Click()
    End
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Winsock1.GetData Response ' Check for incoming response *IMPORTANT*
End Sub


[此贴子已经被作者于2018-6-11 14:18编辑过]


不要選我當版主
2018-06-11 14:17
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:12
帖 子:1668
专家分:3571
注 册:2011-3-24
  得分:0 
Winsock只写过FTP传档案~没试过用来传邮件~

我觉得还是说一下~我是在XP上用VB6开发的Send Mail~
但是是要在Windows2012 R2上运作的~

[此贴子已经被作者于2018-6-11 14:23编辑过]


不要選我當版主
2018-06-11 14:21
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:12
帖 子:1668
专家分:3571
注 册:2011-3-24
  得分:0 
https://bbs.csdn.net/topics/70230675

代码出处~

不要選我當版主
2018-06-11 14:24
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:12
帖 子:1668
专家分:3571
注 册:2011-3-24
  得分:0 
结果成功了~之前收不到信的原因是~我同时开启两种网卡~一张公司内部的~一张苹果的~
结果苹果的一切掉~信就进来了~不过还得试试2012行不行~因为成功的不是用贴上的这个~

是用另一个元件Windows内建的CDO.Message~
CDOSYS.dll要去References这个DLL~再写代码~

不要選我當版主
2018-06-11 14:31
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:12
帖 子:1668
专家分:3571
注 册:2011-3-24
  得分:0 
以下是引用wube在2018-6-11 14:31:42的发言:

结果成功了~之前收不到信的原因是~我同时开启两种网卡~一张公司内部的~一张苹果的~
结果苹果的一切掉~信就进来了~不过还得试试2012行不行~因为成功的不是用贴上的这个~

是用另一个元件Windows内建的CDO.Message~
CDOSYS.dll要去References这个DLL~再写代码~


经过确认此元件只要是Windows OS都能用,所有版本此DLL可供使用,当然也包含Server版OS〜
泛用性比.Net还更广泛,且不需要装任何编译器或SDK或修补档,即可直接使用〜

[此贴子已经被作者于2018-6-14 04:00编辑过]


不要選我當版主
5 天前 03:58
wufuzhang
Rank: 2
等 级:论坛游民
威 望:1
帖 子:19
专家分:84
注 册:2017-8-9
  得分:0 
推荐一个控件jMail.dll,使用方法简单,功能齐全,
也是SMTP协议发送邮件,设置好服务器,很容易发送邮件。
5 天前 09:04







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.345763 second(s), 8 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved