以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  邮箱发送失败  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=189555)

--  作者:ycs5801
--  发布时间:2023/12/8 11:07:00
--  邮箱发送失败

 Dim msg1 As String \'’做邮箱发送设置
        Dim m1 As New MailSender
        m1.Host = "smtp.139.com"
        m1.EnableSsl = True \'必须将EnableSsl属性设置为True
        m1.Account = "scy"
        m1.Password = "xxx"
        m1.From = "scy@139.com"
        messagebox.Show("1")
        m1.Title = "船舶申报提醒"       
        msg1 = dr("船舶代理") & "已申报船名:" & dr("中文船名") & ",请按要求进行后续工作"      
        m1.Content = msg1
       
        Dim zbkz As String
        Dim zbgy As String
        Dim dr1 As DataRow
        dr1 = DataTables("列表项目").SQLFind("值班日期=\'" & Date.Today & "\'")
       messagebox.Show("2")
       
        If dr1 IsNot Nothing Then \'如果找到的话
                 messagebox.Show("3")
           
            If dr1("值班关员") <> "" Then
                    messagebox.Show("4")
                Dim Values() As String
                Values = dr1("值班关员").split("、")
                If values.length > 0 Then
                    For index As Integer = 0 To values.Length - 1
                        Dim dr2 As DataRow = DataTables("登录用户").SQLFind("用户姓名=\'" & values(index) & "\'")
                        If dr2 IsNot Nothing Then
                                 messagebox.Show("5")
                            m1.To = dr2("手机号") & "@139.com"
                            messagebox.Show(dr2("手机号"))
                            m1.SendAsync()
                        End If
                    Next
                End If
               
            End If

 

设置的中断显示都正常,但是没有收到邮件,也没有发送记录,什么原因呢?


--  作者:有点蓝
--  发布时间:2023/12/8 11:12:00
--  
每个用户都要new一个MailSender,要把邮件所有代码都放到循环里


                    For index As Integer = 0 To values.Length - 1
                        Dim dr2 As DataRow = DataTables("登录用户").SQLFind("用户姓名=\'" & values(index) & "\'")
                        If dr2 IsNot Nothing Then
       Dim m1 As New MailSender
        m1.Host = "smtp.139.com"
        m1.EnableSsl = True \'必须将EnableSsl属性设置为True
        m1.Account = "scy"
……
……
                                 messagebox.Show("5")
                            m1.To = dr2("手机号") & "@139.com"
                            messagebox.Show(dr2("手机号"))
                            m1.SendAsync()
                        End If
                    Next

--  作者:有点蓝
--  发布时间:2023/12/8 11:13:00
--  
另外如果邮件服务商没有指定要使用ssl的,把下面代码去掉

m1.EnableSsl = True

--  作者:ycs5801
--  发布时间:2023/12/8 11:17:00
--  

统一都用Dim m1 As New MailSender这个m1行吗?还是每次都需要变一下,如:m1、m2、m3?


--  作者:有点蓝
--  发布时间:2023/12/8 11:25:00
--  
循环里一个名称就行了。您见过帮助的代码循环里定义变量会有不同的嘛
--  作者:ycs5801
--  发布时间:2023/12/8 11:28:00
--  

我现在偶尔能收到,偶尔收不到,我看发送列表,每次只发了一个。代码如下:

  Dim Values() As String
                Values = dr1("值班关员").split("、")
                If values.length > 0 Then
                    For index As Integer = 0 To values.Length - 1
                        Dim dr2 As DataRow = DataTables("登录用户").SQLFind("用户姓名=\'" & values(index) & "\'")
                        If dr2 IsNot Nothing Then
                            messagebox.Show("5")
                            Dim msg1 As String \'’做邮箱发送设置
                            Dim m1 As New MailSender
                            m1.Host = "smtp.139.com"
                            m1.EnableSsl = True \'必须将EnableSsl属性设置为True
                            m1.Account = "scy1"
                            m1.Password = "sss"
                            m1.From = "scy1@139.com"
                            messagebox.Show("1")
                            m1.Title = "船舶申报提醒"
                            msg1 = dr("船舶代理") & dr("用户姓名") & "已申报船名:" & dr("中文船名") & ",请按要求进行后续工作。"
                            m1.Content = msg1
                            m1.To = dr2("手机号") & "@139.com"
                            messagebox.Show(dr2("手机号"))
                            m1.SendAsync()
                        End If
                    Next
                End If
               
            End If


--  作者:有点蓝
--  发布时间:2023/12/8 11:47:00
--  
能够收到,说明代码没有问题。

现在很多邮箱都有防垃圾处理策略,短时间内频繁发送会有限制的

--  作者:ycs5801
--  发布时间:2023/12/8 14:28:00
--  

   dr1 = DataTables("列表项目").SQLFind("值班日期=\'" & Date.Today & "\'")
           
        If dr1 IsNot Nothing Then \'如果找到的话      
            If dr1("值班关员") <> "" Then
                Dim Values() As String
                Values = dr1("值班关员").split("、")
                If values.length > 0 Then
                    Dim msg1 As String \'’做邮箱发送设置
                    Dim m1 As New MailSender
                    m1.Host = "smtp.139.com"
                                               m1.EnableSsl = True \'必须将EnableSsl属性设置为True
                    m1.Account = "scy1"
                    m1.Password = "xxx"
                    m1.From = "scy1@139.com"                                           
                   
                    For index As Integer = 0 To values.Length - 1
                        Dim dr2 As DataRow = DataTables("登录用户").SQLFind("用户姓名=\'" & values(index) & "\'")
                        If dr2 IsNot Nothing Then
                            messagebox.Show(dr2("邮箱地址"))
                            m1.AddReceiver(dr2("邮箱地址"))                         
                        End If
                    Next
                    m1.Title = "船舶申报提醒"
                    msg1 = dr("船舶代理") & dr("用户姓名") & "已申报船名:" & dr("中文船名") & ",请按要求进行后续工作。"
                    m1.Content = msg1
                    m1.SendAsync()
                End If
               
            End If
           

这样可以吗?现在还是无法发送


--  作者:有点蓝
--  发布时间:2023/12/8 14:36:00
--  
m1.SendAsync()改为m1.Send看提示什么错误
--  作者:ycs5801
--  发布时间:2023/12/8 14:45:00
--  
显示上传失败,chrome中显示404错误