1. 程式人生 > >vb.net 傳送電子郵件方法 無需改動 直接Ctrl C V

vb.net 傳送電子郵件方法 無需改動 直接Ctrl C V

 Public Function Emilsend(ByVal arrp As Array) As Boolean

        Dim tConsultname As String = G_objService.SB_MyTrim(arrp(0))
        Dim tConsultTel As String = G_objService.SB_MyTrim(arrp(1))

        Dim tConsultNote As String = G_objService.SB_MyTrim(arrp(2))
        Dim ttyperr As String = G_objService.SB_MyTrim(arrp(3))
        Dim tcompany As String = G_objService.SB_MyTrim(arrp(4))

        Dim temail As String = G_objService.SB_MyTrim(arrp(5))
        Try

            Dim Strname1 As String
            If ttyperr = "0" Then
                Strname1 += "食品abcdefg"
            Else
                Strname1 += "化妝品abcdefg"
            End If


            'Dim StrEMail As String = "
[email protected]
;[email protected]" Dim strFile As String = " Michael:" & vbCr & vbLf strFile = strFile & vbCr & vbLf strFile = strFile & tConsultNote & vbCr & vbLf strFile = strFile & " Contactor:" & tConsultname & vbCr & vbLf strFile = strFile & " Tel:" & tConsultTel & vbCr & vbLf ' Dim strFileOut As String = GetInfoOut(G_objService) ' Dim strFileInventory As String = GetInfoInventory(G_objService) G_objService.Sys_WriteDebug("strFile", strFile) 'G_objService.Sys_WriteDebug("strFileOut", strFileOut) 'G_objService.Sys_WriteDebug("strFileInventory", strFileInventory) sendMail("smtp.abcdefg.net", "ab
[email protected]
", "abcdefg", "", "[email protected]", "[email protected]", Strname1, strFile) 'SendProjectEmailNew(G_objService, StrEMail, "" & Now.Date & "出入庫貨物查詢日報表", strFile, strFileOut, strFileInventory) 'G_objService.Sys_EMailSendMail("smtp.abcdefg.com", "
[email protected]
", "whsafe01", "[email protected]", StrEMail, "", "", Now.Date & "安全庫存日報表", "", "", "GB2312", strFile) G_objService = Nothing Return True Catch ex As Exception G_objService.Sys_WriteDebug("conTaskKey", "---" & ex.Message) Return False End Try End Function Public Sub sendMail(ByVal smtpserver As String, ByVal userName As String, ByVal pwd As String, ByVal nickName As String, ByVal strfrom As String, ByVal strto As String, ByVal subj As String, ByVal bodys As String, Optional ByVal isSSL As Boolean = True) Try Dim _smtpClient As New SmtpClient() _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network _smtpClient.EnableSsl = True _smtpClient.Host = smtpserver _smtpClient.Port = 465 _smtpClient.UseDefaultCredentials = True ' 使用SMTP使用者名稱和密碼進行驗證 _smtpClient.Credentials = New System.Net.NetworkCredential(userName, pwd) '使用者名稱和密碼 Dim _from As New MailAddress(strfrom, nickName) Dim _to As New MailAddress(strto) Dim _mailMessage As New MailMessage(_from, _to) _mailMessage.Subject = subj '主題 _mailMessage.SubjectEncoding = System.Text.Encoding.UTF8 _mailMessage.Body = bodys '內容 _mailMessage.BodyEncoding = System.Text.Encoding.UTF8 '正文編碼 _mailMessage.IsBodyHtml = False '設定為HTML格式 _mailMessage.Priority = MailPriority.Normal '優先順序 _smtpClient.Send(_mailMessage) Catch ex As Exception G_objService.Sys_WriteDebug("sendMail", ex.Message) End Try End Sub