udayrapalli
asked on
How to send email to more than 1000 people in asp.net C# in a click...?
I want to send some invitation email to all the members registered in to the site in one click. There email ids are stored in the database. I enter the text in the textbpx and then say send email... How to send email to all the members if they are in hundreds and may be in thousands in long run...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, and maybe more...it will depend on the Relay settings of your SMTP provider. 10 should be a "safe" number, but you should test to find the best value.
ASKER
Hello there,
Thank you for the help, I am new to this field and i have used namespace - using System.Net.Mail; and the code is here...
MailMessage HTMLMail = new MailMessage();
HTMLMail.From = new MailAddress("info@domain", fromName);
HTMLMail.To.Add(new MailAddress(mailTo));
HTMLMail.Subject = Subject;
HTMLMail.IsBodyHtml = true;
HTMLMail.Body = spEmailMatter.ToString();
SmtpClient client = new SmtpClient("localhost", 25);
client.Send(HTMLMail);
Now I am confused.. how to send 10 and again 10 and so on... is that what i written is good ... for the solution I am searching for... ?
Thank you for the help, I am new to this field and i have used namespace - using System.Net.Mail; and the code is here...
MailMessage HTMLMail = new MailMessage();
HTMLMail.From = new MailAddress("info@domain",
HTMLMail.To.Add(new MailAddress(mailTo));
HTMLMail.Subject = Subject;
HTMLMail.IsBodyHtml = true;
HTMLMail.Body = spEmailMatter.ToString();
SmtpClient client = new SmtpClient("localhost", 25);
client.Send(HTMLMail);
Now I am confused.. how to send 10 and again 10 and so on... is that what i written is good ... for the solution I am searching for... ?
ASKER
Hello there,
Thank you for the help, I am new to this field and i have used namespace - using System.Net.Mail...
Now I am confused.. how to send 10 and again 10 and so on... is that what i written is good ... for the solution I am searching for... ?
Thank you for the help, I am new to this field and i have used namespace - using System.Net.Mail...
Now I am confused.. how to send 10 and again 10 and so on... is that what i written is good ... for the solution I am searching for... ?
MailMessage HTMLMail = new MailMessage();
HTMLMail.From = new MailAddress("info@domain", fromName);
HTMLMail.To.Add(new MailAddress(mailTo));
HTMLMail.Subject = Subject;
HTMLMail.IsBodyHtml = true;
HTMLMail.Body = spEmailMatter.ToString();
SmtpClient client = new SmtpClient("localhost", 25);
client.Send(HTMLMail);
I have a script, in VB, that loops through the DB, pulling Name + e-Mail address...
It then sends messages to each recipient... the reason I do this is so that I can mail-merge their details, and more specifically their Unsubscribe details...
The script runs in a background thread and handles about 50,000 messages per hour...
(It does embedding of images and attachments too...)
It then sends messages to each recipient... the reason I do this is so that I can mail-merge their details, and more specifically their Unsubscribe details...
The script runs in a background thread and handles about 50,000 messages per hour...
(It does embedding of images and attachments too...)
Private Sub SendEmails()
Dim smtp As New System.Net.Mail.SmtpClient
'Dim MSUAdaptor As New SQLDataSetTableAdapters.MessagesSentUserTableAdapter
Dim MemAdaptor As New SQLDataSetTableAdapters.aspnet_MembershipTableAdapter
Dim BGAdaptor As New SQLDataSetTableAdapters.BGThreadTableAdapter
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("connSQL").ConnectionString)
Dim cmd As New SqlCommand
cmd.Connection = conn
' add to messages sent...
cmd.CommandText = "INSERT INTO MessagesSent (Subject, Body, FromName, FromEmail) VALUES ('" & Misc.DoRep(txtSubject.Text, 100) & "','" & _
Misc.DoRepNQ(MailBodyBeforeInlineImageReplace, 5000000) & "','" & Misc.DoRep(txtFromFirstName.Text & " " & txtFromLastName.Text, 100) & "','" & Misc.DoRep(txtFromEmail.Text, 150) & "') SELECT @@IDENTITY"
conn.Open()
Dim MessageSentId As Integer = cmd.ExecuteScalar
conn.Close()
For i As Integer = 0 To CheckBoxListLists.Items.Count - 1
If CheckBoxListLists.Items(i).Selected = True Then
' send to this list...
cmd.CommandText = "SELECT U.UserId, MEM.firstname, MEM.lastname, MEM.email from aspnet_membership AS MEM INNER JOIN " & _
"aspnet_users AS U ON U.UserId = MEM.UserId INNER JOIN userMailingLists AS UM ON U.UserId = UM.[user]" & _
"INNER JOIN mailingLists AS M ON M.mailingListId = UM.mailingList WHERE M.mailingListId = '" & CheckBoxListLists.Items(i).Value & "' AND (MEM.Unsub = 0) AND (MEM.EmailBounced <= 4 OR MEM.EmailBounced IS NULL) AND (MEM.LastSendRef <> '" & Misc.DoRep(txtReferenceNumber.Text, 50) & "' OR MEM.LastSendRef IS NULL)"
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
While dr.Read
Dim mm As New System.Net.Mail.MailMessage()
mm.From = New System.Net.Mail.MailAddress(txtFromEmail.Text, txtFromFirstName.Text & " " & txtFromLastName.Text)
mm.ReplyTo = New System.Net.Mail.MailAddress(txtReplyToEmail.Text, txtFromFirstName.Text & " " & txtFromLastName.Text)
Dim mmAddress As New MailAddress(dr("Email"))
mm.To.Add(mmAddress)
mm.Subject = txtSubject.Text
'Get the full message body...
GetFullHTMLBody()
' Attach a File
If AttachmentDropDownList.SelectedIndex > 0 Then
Dim attachFile As New Attachment(Session("PhysicalApplicationPath") & "userfiles\image\mailpics\attachments\" & AttachmentDropDownList.SelectedValue)
mm.Attachments.Add(attachFile)
End If
' attach any images...
AttachInlineImages(mm)
mm.IsBodyHtml = True
mm.Body = ""
Dim RecipientMailBody As String = ""
' merge details...
RecipientMailBody = MailBody
RecipientMailBody = Replace(RecipientMailBody, "%%FirstName%%", dr("FirstName"), , , CompareMethod.Text)
RecipientMailBody = Replace(RecipientMailBody, "%%LastName%%", dr("LastName"), , , CompareMethod.Text)
RecipientMailBody = Replace(RecipientMailBody, "%%Email%%", dr("Email"), , , CompareMethod.Text)
mm.Body = RecipientMailBody
' send message
Try
smtp.Send(mm)
' mark recipient as message sent...
'MSUAdaptor.InsertRec(MessageSentId, dr("UserId"))
MemAdaptor.UpdateLastSendRef(txtReferenceNumber.Text, dr("UserId"))
Catch ex As Exception
BGAdaptor.InsertError(ex.ToString)
Finally
mm = Nothing
End Try
Session("EmailCount") += 1
End While
conn.Close()
' mark list as sent...
cmd.CommandText = "INSERT INTO MailingListMessagesSent (mailingList, message) VALUES (" & CheckBoxListLists.Items(i).Value & "," & MessageSentId & ")"
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End If
Next
cmd.Dispose()
conn.Dispose()
Session("EmailCount") = Session("TotalEmails")
End Sub
ASKER
Can I send ten email id seperated with comma in a text field at one go...