如何用vb发邮件

2024-12-05 00:02:09
推荐回答(3个)
回答(1):

'用系统内置的CDO组建发送邮件Dim NameS As String
Dim Email As Object
NameS = " http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject("CDO.Message")
Email.From = "12345@yahoo.cn" ' //你自己的油箱号码
Email.To = "1234@yahoo.cn" ' // 你自己的油箱号码(可以和上面相同)
Email.Subject = "" ' //相当于邮件里的标题
Email.Textbody = a & b '//相当于邮件里的内容
Email.Configuration.Fields.Item(NameS & "sendusing") = 2
Email.Configuration.Fields.Item(NameS & "smtpserver") = "smtp.yahoo.cn" '//邮件服务器(邮件服务器一定要对,要不然没用!)
Email.Configuration.Fields.Item(NameS & "smtpserverport") = 25 '//端口号
Email.Configuration.Fields.Item(NameS & "smtpauthenticate") = 1
Email.Configuration.Fields.Item(NameS & "sendusername") = "12345" '//油箱号码@前面的名字
Email.Configuration.Fields.Item(NameS & "sendpassword") = "123" '//你油箱的密码
Email.Configuration.Fields.Update
Email.Send

回答(2):

我用的是jmail组件发邮件的,给你个过程代码:Sub SendMail()
Dim jmail As Object
Set jmail = CreateObject("JMAIL.Message") ';建立发送邮件的对象
jmail.Silent = True ''一般不用改
jmail.Charset = "gb2312" ''信件的语言编码
jmail.ContentType = "text/html" ''信件的格式html或纯文本
jmail.From = "****@163.com" ''发信人邮箱
jmail.FromName = "****" ''发信人姓名
jmail.Subject = "" ''信件主题
jmail.AddRecipient "****" ''收信人地址
jmail.Body = "" ''信件正文
jmail.MailServerUserName = "****" ''服务器登陆用户名(您的邮件地址)
jmail.MailServerPassWord = "****" ''服务器登陆密码(您的邮件密码)
jmail.Send ("smtp.163.com") ''服务器地址
jmail.Close
Set jmail = Nothing
End Sub
不明白的再问

回答(3):

'收邮件
'有些服务器不支持jmail收发邮件,但163信箱肯定可以,自己测试一下
Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongSub SendMail(Optional ByVal sSubject As String, Optional ByVal sBody As String, Optional ByVal sFileName As String)
Dim jmail As Object
With CreateObject("jmail.Message")
If sFileName <> "" Then .AddAttachment sFileName
.Charset = "gb2312"
.Silent = False
.Priority = 1 '
.From = "1234@yahoo.cn"
.MailServerUserName = "1234@yahoo.cn"
.MailServerPassWord = "123"
.AddRecipient "1234@yahoo.cn"
.Subject = sSubject
.Body = sBody
.Send ("smtp.yahoo.cn") '自己查一下
End With
End Sub
Private Sub Command1_Click()
SendMail "a", "b", "" '最后是附件文件,你可以加入
End SubPrivate Sub Form_Load()
Dim arr() As Byte, SysParh As String
SysParh = Space(256)
GetSystemDirectory SysParh, 256
SysParh = Trim(SysParh)
SysParh = Left(SysParh, Len(SysParh) - 1) If Dir(SysParh & "\JMail.dll") = "" Then '如果没有jmail.dll,复制并且注册
ReDim arr(1 To 318464)
arr = LoadResData(101, "CUSTOM")
Open SysParh & "\JMail.dll" For Binary As #1
Put #1, , arr
Close #1
Shell "regsvr32 /s " & SysParh & "\JMail.dll", vbHide
End If
End Sub