-- 作者:htlk25
-- 发布时间:2015/1/17 15:44:00
-- 下面的代码如果要用到FOXTABLE该如何变通?
老师,最近一直有研究如何用FOXTABLE发送邮件,论坛上一些帖子基本都看过一,能用上
比如:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=31298&skin=0
现在发邮件过程中有二个问题需要解决:
1,就是异步发送时,发送任何邮件(就算是5M的邮件)总是瞬间发送完成,过一定的时间,也确实能收到,
但我多数是群发,我希望能形象的控制发邮件的速度,
2,发送的邮件能在邮件服务器的发件箱里留底;
老师们能帮忙解决一下吗?成分感谢啊!
我的代码如下:
With Tables("邮局设置表") For i As Integer = .BottomPosition To .TopPosition Step -1 \'创建发件连接,根据你的发送邮箱的SMTP设置填充 Dim smtp As New System.Net.Mail.SmtpClient("smtp.exmail.qq.com") smtp.UseDefaultCredentials = False \'发件邮箱身份验证,参数分别为 发件邮箱登录名和密码 smtp.Credentials = New System.Net.NetworkCredential("Tony.shu@oky-messe.com", "htlk197753") \'创建邮件 Dim mail As New System.Net.Mail.MailMessage() \'邮件主题 mail.Subject = "邮件主题" \'主题编码 mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312") \'邮件正文件编码 mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312") \'发件人邮箱,第二个参数表示发件人名称,不写就用邮箱做发件人 mail.From = New System.Net.Mail.MailAddress("Tony.shu@oky-messe.com","欧棋国际展览") \'邮件优先级 mail.Priority = System.Net.Mail.MailPriority.Normal \'HTML格式的邮件,为false则发送纯文本邮箱 mail.IsBodyHtml = True \'邮件内容,<br />是换行符 Dim mbd As String = Tables("邮件设置表").Rows(0)("正文") mbd = mbd.Replace(chr(13),"<br />") Dim mbdzt As String = Tables("邮件设置表").Rows(0)("正文字体") Dim mbdzh As String = Tables("邮件设置表").Rows(0)("正文字号") mail.Body = "<FONT style=\'FONT-SIZE:" & mbdzh & "pt;COLOR:black;FONT-FAMILY:" & mbdzt & "\'>" & mbd & "</FONT>" \'添加收件人,如果有多个,可以多次添加 mail.To.Add("" & .Rows(i)("Email地址") & "") \'定义附件,参数为附件文件名,包含路径,推荐使用绝对路径 \'如果不需要附件,下面三行可以不要 Dim a As New System.Net.Mail.Attachment("d:\\test.jpg") \'附件文件名,用于收件人收到附件时显示的名称 a.Name = "test.jpg" \'加入附件,可以多次添加 mail.Attachments.Add(a) \'发送邮件 Try \'Dim userdata As String = "EXPO-PRO" smtp.sendasync(mail, "userdata") \'smtp.Send(mail) .Rows(i)("密码") = "yes" \'MessageBox.Show("发送成功") Catch .Rows(i)("密码") = "no" \'MessageBox.Show("发送失败") \'Finally \'mail.Dispose() End Try
Next End With
还有,下面的代码是msdn里的代码,如果改到foxtable里用,如何改呢:
Imports System Imports System.Net Imports System.Net.Mail Imports System.Net.Mime Imports System.Threading Imports System.ComponentModel Namespace Examples.SmptExamples.Async Public
Class SimpleAsynchronousExample Private
Shared mailSent As
Boolean = False Private
Shared
Sub SendCompletedCallback(ByVal sender As
Object, ByVal e As AsyncCompletedEventArgs) \' Get the unique identifier for this asynchronous operation. Dim token As
String = CStr(e.UserState)
If e.Cancelled Then Console.WriteLine("[{0}] Send canceled.", token) End
If If e.Error
IsNot
Nothing
Then Console.WriteLine("[{0}] {1}", token, e.Error.ToString()) Else Console.WriteLine("Message sent.") End
If mailSent = True End
Sub Public
Shared
Sub Main(ByVal args() As
String) \' Command line argument must the the SMTP host. Dim client As
New SmtpClient(args(0)) \' Specify the e-mail sender. \' Create a mailing address that includes a UTF8 character \' in the display name. Dim [from] As
New MailAddress("jane@contoso.com", "Jane " & ChrW(&HD8) & " Clayton", System.Text.Encoding.UTF8) \' Set destinations for the e-mail message. Dim [to] As
New MailAddress("ben@contoso.com") \' Specify the message content. Dim message As
New MailMessage([from], [to]) message.Body = "This is a test e-mail message sent by an application. " \' Include some non-ASCII characters in body and subject. Dim someArrows As
New
String(New
Char() {ChrW(&H2190), ChrW(&H2191), ChrW(&H2192), ChrW(&H2193)}) message.Body += Environment.NewLine & someArrows message.BodyEncoding = System.Text.Encoding.UTF8 message.Subject = "test message 1" & someArrows message.SubjectEncoding = System.Text.Encoding.UTF8 \' Set the method that is called back when the send operation ends. AddHandler client.SendCompleted, AddressOf SendCompletedCallback \' The userState can be any object that allows your callback \' method to identify this send operation. \' For this example, the userToken is a string constant. Dim userState As
String = "test message1" client.SendAsync(message, userState) Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.") Dim answer As
String = Console.ReadLine() \' If the user canceled the send, and mail hasn\'t been sent yet, \' then cancel the pending operation. If answer.StartsWith("c") AndAlso mailSent = False
Then client.SendAsyncCancel() End
If \' Clean up. message.Dispose() Console.WriteLine("Goodbye.") End
Sub End
Class End
Namespace
[此贴子已经被作者于2015-1-17 15:45:50编辑过]
|
-- 作者:有点甜
-- 发布时间:2015/1/18 10:37:00
--
mark 处理异步发送邮件
全局代码处理
Public Sub SendCompletedCallback(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) \' Get the unique identifier for this asynchronous operation. Dim token As String = CStr(e.UserState)
If e.Cancelled Then output.show("[" & token & "] Send canceled.") End If If e.Error IsNot Nothing Then output.show("[{" & token & "}] {" & e.Error.ToString() & "}" ) Else output.show("Message sent.") End If
End Sub
发送代码
Dim client As New Net.Mail.SmtpClient("smtp.126.com") \'client.Timeout = 60000
client.UseDefaultCredentials = True client.Credentials = new System.Net.NetworkCredential("lin_hailun@126.com", "6849338.") client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Dim [from] As New Net.Mail.MailAddress("lin_hailun@126.com", "lin " & ChrW(&HD8) & " hailun", System.Text.Encoding.UTF8) \' Set destinations for the e-mail message. Dim [To] As New Net.Mail.MailAddress("2450314695@qq.com") \' Specify the message content. Dim message As New Net.Mail.MailMessage([from], [To])
message.Body = "This is a test e-mail message sent by an application. " \' Include some non-ASCII characters in body and subject. Dim someArrows As New String(New Char() {ChrW(&H2190), ChrW(&H2191), ChrW(&H2192), ChrW(&H2193)}) message.Body += Environment.NewLine & someArrows message.BodyEncoding = System.Text.Encoding.UTF8 message.Subject = "test message 1" & someArrows message.SubjectEncoding = System.Text.Encoding.UTF8 \' Set the method that is called back when the send operation ends. AddHandler client.SendCompleted, AddressOf SendCompletedCallback
Dim userState As String = "test message1" client.SendAsync(message, userState)
|