Any current examples of doing batch emails with asp.net?

Any current examples with latest Mail object using asp.net to do batch emails? Wondering what some best practices are especially in utilizing SendAsync from the web. Thanks.

Dan

Dear Dan,

What’s your scenario? Are you going to send bulk mails or mail merge?

If you want to send mail merge, please use the SmptClient.MergeSend, or Merge. For the sample please refer to

[http://www.aspose.com/wiki/default.aspx/Aspose.Network/MailMerge.html ](https://forum.aspose.com/wiki/default.aspx/Aspose.Network/MailMerge.html)

If you want to send bulk mails, please use the SmptClient.BulkSend or BulkSendAsync. For the sample please refer to :

[http://www.aspose.com/wiki/default.aspx/Aspose.Network/MailBulkSending.html ](https://forum.aspose.com/wiki/default.aspx/Aspose.Network/MailBulkSending.html)

Generally speaking, the BulkSend could be a good idea to send multiple mails, since it will only open one mail session with the Smpt Server.

Thanks very much and feel free to access me with any problems.

The example mailClient.BulkSend();

If there are 100's or 1000's of email address in the mail merge will this work? Could you explain the options with batchSize and interval since the documentation if very scarce? This is being called from a web page also so I'd like it not to make the browser wait if it's taking a long time. Does the BulkSend call immediately return? Thanks for any sugegstions.

Dan

Hello Dan,

First of all, thanks you for your support.
And second of all, yes, our documentation is really scarce, what a shame. but, it’s growing now.
Here is a sample of web application of mail BulkSend:

=================
in this sample, there are two sets of mail message input, each set has a..
"from what address" textbox
"to what address" textbox
"content of the message" textbox
besides those, there are a send button

this WebForm1.aspx is as followed:


<asp:button id="Button1" style="Z-INDEX: 101; LEFT: 280px; POSITION: absolute; TOP: 424px" runat="server"
Text="Send" Width="112px" Height="32px">
<asp:textbox id="TextBox_from1" style="Z-INDEX: 102; LEFT: 72px; POSITION: absolute; TOP: 72px"
runat="server" Width="193px" Height="24px">test@aspose.com
<asp:textbox id="TextBox_from2" style="Z-INDEX: 103; LEFT: 408px; POSITION: absolute; TOP: 72px"
runat="server" Width="200px" Height="26px">test2@aspose.com
<asp:TextBox id="TextBox_to1" style="Z-INDEX: 104; LEFT: 72px; POSITION: absolute; TOP: 104px"
runat="server" Width="192px" Height="24px">me@aspose.com
<asp:TextBox id="TextBox_to2" style="Z-INDEX: 105; LEFT: 408px; POSITION: absolute; TOP: 104px"
runat="server" Width="200px" Height="24px">me@aspose.com
<asp:TextBox id="TextBox_content1" style="Z-INDEX: 106; LEFT: 72px; POSITION: absolute; TOP: 192px"
runat="server" Width="192px" Height="216px">hello, It's me
<asp:TextBox id="TextBox_content2" style="Z-INDEX: 107; LEFT: 408px; POSITION: absolute; TOP: 192px"
runat="server" Width="200px" Height="208px">that's me again!
<asp:Label id="Label1" style="Z-INDEX: 108; LEFT: 24px; POSITION: absolute; TOP: 72px" runat="server"
Width="48px">from:
<asp:Label id="Label2" style="Z-INDEX: 109; LEFT: 24px; POSITION: absolute; TOP: 120px" runat="server"
Width="40px" Height="24px">to:
<asp:Label id="Label3" style="Z-INDEX: 110; LEFT: 352px; POSITION: absolute; TOP: 72px" runat="server"
Width="64px" Height="24px">from:
<asp:Label id="Label4" style="Z-INDEX: 111; LEFT: 352px; POSITION: absolute; TOP: 112px" runat="server"
Width="56px" Height="24px">to:
<asp:Label id="Label5" style="Z-INDEX: 112; LEFT: 24px; POSITION: absolute; TOP: 160px" runat="server"
Width="72px" Height="40px">contents:
<asp:Label id="Label6" style="Z-INDEX: 113; LEFT: 352px; POSITION: absolute; TOP: 152px" runat="server"
Width="72px" Height="32px">contents:
<asp:Label id="Label7" style="Z-INDEX: 114; LEFT: 24px; POSITION: absolute; TOP: 16px" runat="server"
Width="416px" Height="24px">Aspose.Network.Mail web application bulk send demo:

=================
And it's corresponding code-behind WebForm1.aspx.vb only has one importand "send" button sub:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'for 3 secs delay simulation
'System.Threading.Thread.Sleep(3000)

Dim msg1, msg2 As Aspose.Network.Mail.MailMessage
Dim destination As Aspose.Network.Mail.MailAddressCollection

msg1 = New MailMessage
msg1.From = New Aspose.Network.Mail.MailAddress(TextBox_from1.Text)
destination = New MailAddressCollection
destination.Add(New MailAddress(TextBox_to1.Text))
msg1.To = destination

msg2 = New MailMessage
msg2.From = New Aspose.Network.Mail.MailAddress(TextBox_from2.Text)
destination = New MailAddressCollection
destination.Add(New MailAddress(TextBox_to2.Text))
msg2.To = destination

Dim client As Aspose.Network.Mail.SmtpClient
client = New SmtpClient("mail.aspose.com", 25) 'smtp server port: 25
'there are two mail message to send
client.AddMessage(msg1)
client.AddMessage(msg2)

'try to send 1 msg at a time (per batch)
client.SendBatchSize = 1

'pause for 1000ms when a batch of messages have been sent
client.SendBatchInterval = 1000

Try
client.BulkSend()
Catch ex As Exception
End Try

'tell the user, mail messages have been sent
Button1.Text = "sent"
Button1.Enabled = False

End Sub

what this sub does is..
1.create 2 MailMessage
2.create a SmtpClient
3.add those msg to that client
4.use SmtpClient to send these 2 msgs

SmtpClient will send several msgs per batch, pasuse for sometime, then send another batch
each batch contains SendBatchSize of msgs
each pause cost SendBatchInterval milliseconds


=================
when you are using async functions , after you call a begin*** function, the program will go on, you don't have to wait for that *** operation to finish, you can

retrieve the *** operation result later (e.g, in a finished event handler). And if you are not using async functions and you want to achieve the same effect, you could

start a thread to run that *** (sync) operation.

Although there are async send functions in SmtpClient, but as we all know in a web application, The processing cycle for an ASP.NET Web page is this:

1.The user requests the page. (The page is requested using an HTTP GET method.) The page runs for the first time, performing preliminary processing if you have programmed it to do so.

2.The page dynamically renders markup to the browser, which the user sees as a Web page similar to any other static page.

3.The user types information or selects from available choices and then clicks a button. (If users click a link instead of a button, the page might simply navigate to another page, and no further processing takes place on the first page.)

4.The page is posted to the Web server. (The browser performs an HTTP POST, which in ASP.NET is referred to as a postback.) Specifically, the page is posted back to itself. For example, if the user is working with page Default.aspx, clicking a button on the page posts the page back to the server with a target of Default.aspx.

5.On the Web server, the page runs again. The information that the user typed or selected is available to the page.

6.The page performs the processing that you have programmed it to do.

7.The page renders itself back to the browser.

Because of that, those async functions in SmtpClient could not directly affects the browser response time, yet we could use other technique to do that, for example, If you are using ASP.NET 2.0, I think we could use ICallbackEventHandler interface and RaiseCallbackEvent to design a "Client Callbacks Without Postbacks" scheme. in that case, throughout the calling server function process, the web page is living in the browser. I will post that details later.

thanks