我正在尝试向未知号码发送电子邮件邀请。的人,我希望我可以使用线程来稍微提高速度。任何人都可以请教我所做的是否有任何帮助或完全无关紧要。谢谢。
Public Shared Function Emailing_FriendInvitation(ByVal memberID As String _
, ByVal referrerCode As String _
, ByVal enquiryCode As String _
, ByVal outletCode As String _
, ByVal templateName As String _
, ByVal emailAddressLists As List(Of String) _
, ByVal dbtrans As DbTransaction _
, ByVal dbConnection As DbConnection _
, ByVal addedBy As String _
, ByVal customerCode As String) As Boolean
Dim dbCommand As DbCommand = Nothing
Dim isSuccess As Boolean = False
Try
Dim senderEmailName As String = String.Empty
Dim senderEmail As String = String.Empty
Dim receipientEmail As String = String.Empty
Dim receipientName As String = "Dear Sir/Madam"
Dim emailSubject As String = String.Empty
Dim emailBody As String = String.Empty
Dim ds As DataSet = Nothing
If dbConnection.State <> ConnectionState.Open Then
dbConnection.Open()
End If
dbCommand = GetStoredProcedureCommand("FriendsInvitation")
dbCommand.Connection = dbConnection
If Not dbtrans Is Nothing Then
dbCommand.Transaction = dbtrans
End If
Dim emailAddresses As String
For Each email In emailAddressLists
emailAddresses += email + ","
Next
AddInParameter(dbCommand, "@MemberID", DbType.String, memberID)
AddInParameter(dbCommand, "@EmailAddresses", DbType.String, emailAddresses)
AddInParameter(dbCommand, "@TemplateName", DbType.String, 256, templateName)
AddInParameter(dbCommand, "@EnquiryCode", DbType.String, 50, enquiryCode)
AddInParameter(dbCommand, "@OutletCode", DbType.String, 50, outletCode)
AddInParameter(dbCommand, "@ReferrerCode", DbType.String, 50, referrerCode)
AddInParameter(dbCommand, "@AddedBy", DbType.String, 50, addedBy)
ds = ExecuteDataSet(dbCommand)
senderEmailName = Convert.ToString(IIf(Not IsDBNull(ds.Tables(0).Rows(0)("AutoEmailDisplayName")), ds.Tables(0).Rows(0)("AutoEmailDisplayName"), String.Empty))
senderEmail = Convert.ToString(IIf(Not IsDBNull(ds.Tables(0).Rows(0)("AutoEmailSender")), ds.Tables(0).Rows(0)("AutoEmailSender"), String.Empty))
emailSubject = templateName
emailBody = Convert.ToString(IIf(Not IsDBNull(ds.Tables(0).Rows(0)("AutoEmailContent")), ds.Tables(0).Rows(0)("AutoEmailContent"), String.Empty))
'emailBlastRecipientAutoID = Convert.ToString(ds.Tables(1).Rows(0)("EmailBlastRecipientAutoID"))
' End If
If Not (String.IsNullOrEmpty(senderEmail) AndAlso String.IsNullOrEmpty(receipientEmail) AndAlso _
String.IsNullOrEmpty(emailSubject) AndAlso String.IsNullOrEmpty(emailBody)) Then
emailBody = emailBody.Replace("[REFERRERCODE]", "REFERRERCODE")
'----Thread-----
Dim Th = New Thread(Sub() sendEmail(emailAddressLists, senderEmailName, senderEmail, emailSubject, emailBody))
Th.Start()
End If
'---------------
Catch ex As Exception
isSuccess = False
Throw New DALException(ex, dbCommand, customerCode, "Emailing_FriendInvitation")
Finally
If Not dbCommand Is Nothing Then
dbCommand.Dispose()
End If
End Try
Return isSuccess
End Function
Private Shared Sub sendEmail(ByVal emailLst As List(Of String), ByVal senderEmailName As String, ByVal senderEmail As String, ByVal emailSubject As String, ByVal emailBody As String)
Dim successfulReceipents As String = String.Empty
For Each emailAdd In emailLst
Try
Email.Send(senderEmailName, senderEmail, emailAdd, emailSubject, emailBody, Nothing)
successfulReceipents += emailAdd + ","
Catch ex As Exception
End Try
Next
End Sub