对你是太菜的问题,对我就不是

wdthkyou 2006-10-26 02:11:41
学习简单的发送邮件,看了网上的现成代码,试了一下,没有发出去,搞不懂,故此一问:
如果只知道xxxx@126.com,问vb能否用纯代码实现主题、内容、附件直接发送成功,还是需要
知道更多才能完成此功能(例如:pop3).我纯粹一菜鸟,pop3也不知道。希望高手留情,我正在
学嘛。
...全文
198 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wdthkyou 2006-10-28
  • 打赏
  • 举报
回复
邮件已发,请收看。谢谢。
海贼王大妈 2006-10-28
  • 打赏
  • 举报
回复
我有个代码,支持需要密码验证的SMTP服务器,可以发附件
需要的发个邮件给我xiejienet@126.com
wdthkyou 2006-10-27
  • 打赏
  • 举报
回复
上面发送代码改成这样也没有成功:
If msg.Send(txtUserName.Text & ":" & txtPassword.Text & "@smtp.163.com") Then
MsgBox "OK!!"
End If
郁闷,高手啊,看一下嘛!错在哪里!!
wdthkyou 2006-10-27
  • 打赏
  • 举报
回复
zq972(*^_^*) :
你的代码我没有成功,你成功过吗?问一下,163的服务器地址是这样写吗:smtp.163.com
若是这样,我的确不知哪里错了,附代码:
Dim msg As jmail.Message

Dim strarr, contentId
Dim bln As Boolean
Dim intx As Integer

On Error GoTo ErrorHandle

Set msg = CreateObject("JMail.Message")
msg.Logging = True '启用邮件日志
msg.Charset = "gb2312" '邮件的文字编码为国标
msg.AddRecipient txtSendTo.Text '邮件收件人的地址

msg.From = txtaddress.Text '发件人的E-MAIL地址
msg.MailServerUserName = txtUserName.Text '登录邮件服务器所需的用户名 '用户名
msg.MailServerPassWord = txtPassword.Text ''登录邮件服务器所需的密码
msg.subject = Format(Date, "yyyy年mm月dd") & "日调试信息" ' '邮件的标题
msg.Body = "详情见附件。" ' '邮件的内容


msg.Priority = 3 ' '邮件的紧急程序,1 为最快,5 为最慢。 3 为默认值,表示中等
msg.ContentTransferEncoding = "base64"
If txtFileName.Text <> "" Then '附件
If Dir(txtFileName.Text) <> "" Then
contentId = msg.AddAttachment(txtFileName.Text, True) '
End If
End If
If msg.Send("smtp.163.com") Then 'msg.Send(txtusername.Text & ":" & txtpassword.Text & "@" & txthostname.Text)
MsgBox "OK!!"
End If
msg.Close
Set msg = Nothing
Dunzip 2006-10-26
  • 打赏
  • 举报
回复
其实用控件也麻烦,控件只不过已经封装了一个用户或服务器。
wdthkyou 2006-10-26
  • 打赏
  • 举报
回复
txthostname.Text="这里怎样写才是有效的发信服务器地址",以163为例,写成www.163.com不行呀,盼解答。
guoguo1982 2006-10-26
  • 打赏
  • 举报
回复
这个对我也难!!
wdthkyou 2006-10-26
  • 打赏
  • 举报
回复
jmail发邮件需借用一个已存在的邮箱(例如自己的)才能发呀,是这个意思吗?
能直接从本地盘发一份文件出去吗?太菜了,见笑了。谢谢你的耐心!
zq972 2006-10-26
  • 打赏
  • 举报
回复
用户名、密码当然是指的你自己的邮箱用户名和密码啦

就好比你不通过你的用户名和密码登陆163的网站,怎么用163发信呢
wdthkyou 2006-10-26
  • 打赏
  • 举报
回复
我给其他用户传(非恶意,业务往来),他的密码怎能告知我。
wdthkyou 2006-10-26
  • 打赏
  • 举报
回复
要密码才能上传文件吗?
zq972 2006-10-26
  • 打赏
  • 举报
回复
'引用Jmail 4.0 Library
Private Sub Command2_Click()
Dim msg As jmail.Message

Dim strarr
Dim bln As Boolean
Dim intx As Integer

On Error GoTo ErrorHandle

Set msg = CreateObject("JMail.Message")
msg.Logging = True
msg.Charset = "gb2312"
msg.From = txtaddress.Text
msg.FromName = txtname.Text

msg.AddRecipient txtSendTo.Text


If Len(Trim(txtSendAlso.Text)) > 0 Then
strarr = Split(txtSendAlso.Text, ";")
For intx = 0 To UBound(strarr)
msg.AddRecipientCC strarr(intx)
Next
End If
msg.Priority = 3
msg.ContentTransferEncoding = "base64"
If txtFileName.Text <> "" Then'附件
If Dir(txtFileName.Text) <> "" Then
contentId = msg.AddAttachment(txtFileName.Text, True) '
End If
End If
msg.Subject = txtSubject.Text'主题
msg.Body = Text1.Text
msg.MailServerUserName = txtusername.Text'用户名
msg.MailServerPassWord = txtpassword.Text'密码
If msg.Send(txthostname.Text & ":" & txtPort.Text) Then 'msg.Send(txtusername.Text & ":" & txtpassword.Text & "@" & txthostname.Text)
MsgBox "OK!!"
End If
msg.Close
Set msg = Nothing
Exit Sub

ErrorHandle:


End Sub
wdthkyou 2006-10-26
  • 打赏
  • 举报
回复
给个实例,看简单否.
zq972 2006-10-26
  • 打赏
  • 举报
回复
Jmail挺不错的
wdthkyou 2006-10-26
  • 打赏
  • 举报
回复
of123:你的那个库文件 Microsoft CD 1.21 Library,谢谢发一个过来,我的没找到!
cqqxtyb@163.com
wdthkyou 2006-10-26
  • 打赏
  • 举报
回复
找不到库文件 Microsoft CD 1.21 Library
of123 2006-10-26
  • 打赏
  • 举报
回复
应该可以,不过那样就太麻烦了。一般都要借助控件:

'引用 Microsoft CD 1.21 Library' or higher

Private Sub Form_Load()

Dim strSubject, strTxtBody, strTo, strCC, strBCC, strAttachFile
Dim MailServer, MailPort

MailServer = "MAILSERVER"
MailPort = 25 '...probably
strAttachFile = "c:\Attach.pdf" 'you can comment out the "AddAttachment
strSubject = "Subject" 'if you dont wish to use
strTxtBody = "Body"
strTo = "friend@earth.com;secondfriend@earth.com"

Set objCDO = CreateObject("CDO.Message")
Set objCDOConfig = CreateObject("CDO.Configuration")
Set objFields = objCDOConfig.Fields
With objFields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = MailPort
.Item("http://schemas.microsoft.com/cdo/configuration/SendUsing") = 2
.Update
End With
With objCDO
.Configuration = objCDOConfig
.To = strTo
.CC = strCC
.BCC = strBCC
.From = "me@home.com"
.Subject = strSubject
.HTMLBody = strTxtBody
'.AddAttachment (strAttachFile)
.Send
End With
Set objFields = Nothing
Set objCDOConfig = Nothing
Set objCDO = Nothing

End Sub

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧