sending email in .Net

  • Thread starter Thread starter Eduardo Rosa
  • Start date Start date
ok then...
I wrote queue not for ornament, because I've work a lot with ASP and it need
third-party component to do that.
I was hurry and maybe should wrote the word in uppercase because what I
found in google it most 3rd-party too. So I'll ask again, most precise ok
Juan?

A loop with a many e-mail list works in ASP.Net, unlike classic ASP?
Somebody know how I queue e-mail in ASP.Net without 3rd-party component?
 
Eduardo,

when you say "queue", do you mean getting a list of email
addresses from a database and sending emails to all of them ?

If so, here's a sample :

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Web.Mail" %>
<script runat="server">

Sub Page_Load(Src as object, E as EventArgs)

Dim P, U, Em As String
Dim connectionString As String = "server='YourSQLServerName'; trusted_connection=true; database='YourSQLServerDatabase"
Dim dbConnection As IDbConnection = New SqlClient.SqlConnection(connectionString)

Dim queryString As String = "SELECT UserName, Password, Email FROM Users"
Dim dbCommand As IDbCommand = New SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As IDataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection)

While dataReader.Read()
U = dataReader("Username").ToString()
P = dataReader("Password").ToString()
Em = dataReader("Email").ToString()

' Build a MailMessage
Dim mail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mail.From = "(e-mail address removed)"
mail.To = Em
mail.Subject = "Your Email's subject."
mail.BodyFormat = System.Web.Mail.MailFormat.Html

mail.Body="Hello, " & U & ".<p>Your Username is " & U & " and your password is " & P & ".<p>
And the rest of your HMTL message goes here..."

System.Web.Mail.SmtpMail.SmtpServer = "your.smtp.server"
System.Web.Mail.SmtpMail.Send(mail)
End While

End Sub
</script>
<html>
<head>
</head>
<body>
</body>
</html>

When you open that page, an email with the contents you specify
will be sent to every email address in the Email column in the Users
table in your SQL Server Database.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
Using classic ASP that page will execute until all e-mail had be sended, if that number e-mails are big the script can execed the timeout, some components give to server manage the e-mail sendind, so the script runs fast. My doubt is: some class in default .Net library can do that or I need a 3rd party?

exemple of components for classic ASP

AspQMail (http://www.serverobjects.com/comp/AspQMail.htm)

ASPEmail (www.persits.com), por exemplo o o método queue:
Enables message queuing.
False by default. If set to True, specifies that a subsequent call to Send will place the message in a message queue to be processed by EmailAgent.
This is a premium feature.


thanks a lot Juan

"Juan T. Llibre" <[email protected]> escreveu na mensagem Eduardo,

when you say "queue", do you mean getting a list of email
addresses from a database and sending emails to all of them ?

If so, here's a sample :

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Web.Mail" %>
<script runat="server">

Sub Page_Load(Src as object, E as EventArgs)

Dim P, U, Em As String
Dim connectionString As String = "server='YourSQLServerName'; trusted_connection=true; database='YourSQLServerDatabase"
Dim dbConnection As IDbConnection = New SqlClient.SqlConnection(connectionString)

Dim queryString As String = "SELECT UserName, Password, Email FROM Users"
Dim dbCommand As IDbCommand = New SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As IDataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection)

While dataReader.Read()
U = dataReader("Username").ToString()
P = dataReader("Password").ToString()
Em = dataReader("Email").ToString()

' Build a MailMessage
Dim mail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mail.From = "(e-mail address removed)"
mail.To = Em
mail.Subject = "Your Email's subject."
mail.BodyFormat = System.Web.Mail.MailFormat.Html

mail.Body="Hello, " & U & ".<p>Your Username is " & U & " and your password is " & P & ".<p>
And the rest of your HMTL message goes here..."

System.Web.Mail.SmtpMail.SmtpServer = "your.smtp.server"
System.Web.Mail.SmtpMail.Send(mail)
End While

End Sub
</script>
<html>
<head>
</head>
<body>
</body>
</html>

When you open that page, an email with the contents you specify
will be sent to every email address in the Email column in the Users
table in your SQL Server Database.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
re:
if that number e-mails are big the script can execed the timeout

You can increase the timeout, so that the page has time to complete.
Check web.config's <httpRuntime executionTimeout="90" ... />

and set it to however long you need.





Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

Using classic ASP that page will execute until all e-mail had be sended, if that number
e-mails are big the script can execed the timeout, some components give to server manage
the e-mail sendind, so the script runs fast. My doubt is: some class in default .Net
library can do that or I need a 3rd party?

exemple of components for classic ASP

AspQMail (http://www.serverobjects.com/comp/AspQMail.htm)

ASPEmail (www.persits.com), por exemplo o o método queue:
Enables message queuing.
False by default. If set to True, specifies that a subsequent call to Send will place
the message in a message queue to be processed by EmailAgent.
This is a premium feature.


thanks a lot Juan

"Juan T. Llibre" <[email protected]> escreveu na mensagem
Eduardo,

when you say "queue", do you mean getting a list of email
addresses from a database and sending emails to all of them ?

If so, here's a sample :

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Web.Mail" %>
<script runat="server">

Sub Page_Load(Src as object, E as EventArgs)

Dim P, U, Em As String
Dim connectionString As String = "server='YourSQLServerName'; trusted_connection=true;
database='YourSQLServerDatabase"
Dim dbConnection As IDbConnection = New SqlClient.SqlConnection(connectionString)

Dim queryString As String = "SELECT UserName, Password, Email FROM Users"
Dim dbCommand As IDbCommand = New SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As IDataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection)

While dataReader.Read()
U = dataReader("Username").ToString()
P = dataReader("Password").ToString()
Em = dataReader("Email").ToString()

' Build a MailMessage
Dim mail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mail.From = "(e-mail address removed)"
mail.To = Em
mail.Subject = "Your Email's subject."
mail.BodyFormat = System.Web.Mail.MailFormat.Html

mail.Body="Hello, " & U & ".<p>Your Username is " & U & " and your password is " & P &
".<p>
And the rest of your HMTL message goes here..."

System.Web.Mail.SmtpMail.SmtpServer = "your.smtp.server"
System.Web.Mail.SmtpMail.Send(mail)
End While

End Sub
</script>
<html>
<head>
</head>
<body>
</body>
</html>

When you open that page, an email with the contents you specify
will be sent to every email address in the Email column in the Users
table in your SQL Server Database.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
I don't think like that: if I can make that runs faster why let the user sit
front the machine waiting... With a bad server it could take more then 10
min.
That alread happened to me, the server was bad and the list was big
(newsletter for a portal), I don't know how much sending email was improved
in ASP.Net, maybe that works (I'll try) but I doubt...

thanks a lot
 
Back
Top