救命啊~~用smtp协议的dll组建实现的asp邮件程序的问题

luciferous 2005-04-18 06:01:23
如题,用vb写了个dll,使用smtp协议发送邮件的,但是现在普通的邮件能发,html格式的邮件有的时候可以,有的时候不可以,不知道怎么回事情,比如<img src=http://www.zjol.com.cn/images/2005/logo.gif>,这样子的能收到是个图片,但是换成其他的一个图片连接,或者在img里面加点什么参数,比如width什么的,就直接显示源代码了,如果有表格就更加不行了……救命啊
...全文
3692 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
大猫钓鱼 2005-04-20
  • 打赏
  • 举报
回复
兔子兄就是强,什么时候有问题还是问你啊.不过上次那问题你还没帮我解决呢!(用ASP显示XML图片的问题)
luciferous 2005-04-20
  • 打赏
  • 举报
回复
研究了下什么m什么什么规范,在里面加了个东西就好了,代码如下

Lucifer = "Content-type: text/html;charset=""gb2312""" + vbCrLf
Eighth = Fourth + Third + Ninth + Fifth + Sixth + Lucifer

原来就是对的,只是把这两句话换了个位置,所以开始的时候Lucifer这个变量是空的,寒啊……谢谢楼上的
luciferous 2005-04-20
  • 打赏
  • 举报
回复
最离谱的就是有时候一个简单的图片,例如<img src=>,短的可以,长的不可以……那个寒啊
luciferous 2005-04-20
  • 打赏
  • 举报
回复
遇到同行了,呵呵,开心啊,是哪个双引号表示啊?在发邮件的时候内容里面么?谢谢啦,老兄,靠你救命了……
  • 打赏
  • 举报
回复
我知道原因是因为你用的是双引号表示的吧??
  • 打赏
  • 举报
回复
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
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
'端口设置为0,否则在启动程序的时候信就已经发出去了

If Winsock1.State = sckClosed Then
'如果Winsock关闭中
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) + ToNametxt + vbCrLf
' 收件人姓名
Sixth = "Subject:" + Chr(32) + EmailSubject + vbCrLf
' 邮件主题
Seventh = EmailBodyOfMessage + vbCrLf
' 邮件正文
Eighth = Fourth + Third + Ninth + Fifth + Sixth ' 生成SMTP发送邮件所必须的模式
Ninth = "X-Mailer: EBT Reporter v 2.x" + vbCrLf '发送邮件的软件名称,可以自定义

Winsock1.Protocol = sckTCPProtocol ' 设置发送的协议
Winsock1.RemoteHost = MailServerName ' 设置服务器地址
Winsock1.RemotePort = 25
'设置SMTP端口
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)
'等待回应
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
'查看左面3个字符是否为所需要的字符(例如"250")
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, txtToEmailAddress.Text, txtToEmailAddress.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的数据放到Response中
Winsock1.GetData Response ' Check for incoming response *IMPORTANT*

End Sub
哈哈,你跟我用的是一样的代码
luciferous 2005-04-20
  • 打赏
  • 举报
回复
决定不让这个帖子变成铁达尼号……
luciferous 2005-04-18
  • 打赏
  • 举报
回复
代码再下面,这个是dll里面的一个窗体,这个可以直接用vb标准exe工程编译的,我写的dll就是在这个基础上加上一个class
Dim Response As String, Reply As Integer, DateNow As String
Dim first As String, Second As String, Third As String
Dim Fourth As String, Fifth As String, Sixth 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)


If Winsock1.State = sckClosed Then ' Check to see if socet is closed
Winsock1.LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail pre program start
DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
first = "mail from:" + Chr(32) + FromEmailAddress + vbCrLf ' Get who's sending E-Mail address
Second = "rcpt to:" + Chr(32) + ToEmailAddress + vbCrLf ' Get who mail is going to
Third = "Date:" + Chr(32) + DateNow + vbCrLf ' Date when being sent
Fourth = "From:" + Chr(32) + FromName + vbCrLf ' Who's Sending
Fifth = "To:" + Chr(32) + ToNametxt + vbCrLf ' Who it going to
Sixth = "Subject:" + Chr(32) + EmailSubject + vbCrLf ' Subject of E-Mail
Seventh = EmailBodyOfMessage + vbCrLf ' E-mail message body
Ninth = "X-Mailer: EBT Reporter v 2.x" + vbCrLf ' What program sent the e-mail, customize this
Eighth = Fourth + Third + Ninth + Fifth + Sixth ' Combine for proper SMTP sending

MsgBox (Eighth) 'test

Winsock1.Protocol = sckTCPProtocol ' Set protocol for sending
Winsock1.RemoteHost = MailServerName ' Set the server address
Winsock1.RemotePort = 25 ' Set the SMTP Port
Winsock1.Connect ' Start connection

If WaitFor("220") = False Then GoTo closeSock

StatusTxt.Caption = "Connecting...."
StatusTxt.Refresh

Winsock1.SendData ("HELO worldcomputers.com" + vbCrLf)

If WaitFor("250") = False Then GoTo closeSock

StatusTxt.Caption = "Connected"
StatusTxt.Refresh

Winsock1.SendData (first)

StatusTxt.Caption = "Sending Message"
StatusTxt.Refresh

If WaitFor("250") = False Then GoTo closeSock

Winsock1.SendData (Second)

If WaitFor("250") = False Then GoTo closeSock

Winsock1.SendData ("data" + vbCrLf)

If WaitFor("354") = False Then GoTo closeSock


Winsock1.SendData (Eighth + vbCrLf)
Winsock1.SendData (Seventh + vbCrLf)
Winsock1.SendData ("." + vbCrLf)

If WaitFor("250") = False Then GoTo closeSock

Winsock1.SendData ("quit" + vbCrLf)

StatusTxt.Caption = "Disconnecting"
StatusTxt.Refresh

If WaitFor("221") = False Then GoTo closeSock

closeSock: Winsock1.Close
Else
MsgBox (Str(Winsock1.State))
End If

End Sub
Function WaitFor(ResponseCode As String) As Boolean
Start = Timer ' Time event so won't get stuck in loop
Tmr = Timer - Start
While Len(Response) = 0

DoEvents ' Let System keep checking for incoming response **IMPORTANT**
If Tmr > 50 Then ' Time in seconds to wait
MsgBox "SMTP service error, timed out while waiting for response", 64, MsgTitle
WaitFor = False
Exit Function
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
WaitFor = False
Exit Function
End If
Wend
Response = "" ' Sent response code to blank **IMPORTANT**
WaitFor = True
End Function


Private Sub Command1_Click()
SendEmail txtEmailServer.Text, txtFromName.Text, txtFromEmailAddress.Text, txtToEmailAddress.Text, txtToEmailAddress.Text, txtEmailSubject.Text, txtEmailBodyOfMessage.Text
'MsgBox ("Mail Sent")
StatusTxt.Caption = "Mail Sent"
StatusTxt.Refresh
Beep

Close
End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Winsock1.GetData Response ' Check for incoming response *IMPORTANT*

End Sub
  • 打赏
  • 举报
回复
那要看你的dll 的代码了??你不给代码怎么给你解释呢?

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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