hello,
I want to send the mass email to the students. i create a dummy table to send some email to myself, but then i don't recieve anything after i click on the button.
please help. thanks.
here is the code.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.IO
Imports System.Text
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html.simpleparser
Imports iTextSharp.tool.xml
Imports System.Net.Mail
Partial Class DeansList_DistDLLetter
Inherits System.Web.UI.Page
Dim conn As SqlConnection = New SqlConnection()
Private Sub openconnection()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("CollegeDataConnectionString").ConnectionString
conn.Open()
End Sub
Private Sub DLLetterPDF(ByVal semyearstring As String)
openconnection()
Dim SendEmailString As String = "Select * from DeansList" & semyearstring & " WHERE DLStuId Between 1 AND 5"
'Dim SendEmailString As String = "Select TOP(3) * from DeansList" & semyearstring
'Dim SendEmailString As String = "Select TOP(8) * from DeansListSample"
Dim cmdSendEmail As SqlCommand = New SqlCommand(SendEmailString, conn)
Dim rdSendEmail As SqlDataReader = cmdSendEmail.ExecuteReader
If rdSendEmail.HasRows Then
While rdSendEmail.Read
Dim CertFile As String = Server.MapPath("~/DeansList/documents/DeansListLetterPDF.htm")
Dim content As String = File.ReadAllText(CertFile)
content = content.Replace("##sentdate##", Date.Now.ToShortDateString)
content = content.Replace("##firstname##", rdSendEmail("FirstName"))
Dim sr As New StringReader(content)
Dim pdfDoc As New Document(PageSize.LETTER, 50.0F, 50.0F, 10.0F, 10.0F)
Dim memoryStream As New MemoryStream
Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, memoryStream)
writer.SetEncryption(True, rdSendEmail("ID"), "hhd" & semyearstring, PdfWriter.ENCRYPTION_AES_128)
pdfDoc.Open()
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr)
pdfDoc.Close()
Dim bytes As Byte() = memoryStream.ToArray()
memoryStream.Close()
Dim EmailFile As String = Server.MapPath("~/DeansList/documents/DeansListLetterEmail.htm")
Dim emailcontent As String = File.ReadAllText(EmailFile)
emailcontent = emailcontent.Replace("##firstname##", rdSendEmail("FirstName"))
Dim myMesg As MailMessage = New MailMessage
myMesg.Subject = "College of Health and Human Development Dean's List" '& " - " & rdSendEmail("FirstName") & " " & rdSendEmail("LastName") & " (" & rdSendEmail("eEm") & ")"
myMesg.IsBodyHtml = True
myMesg.Body = emailcontent
myMesg.Attachments.Add(New Attachment(New MemoryStream(bytes), "Deans_List_Letter_" & semyearstring & ".pdf"))
'myMesg.Attachments.Add(New Attachment("E:\WebApps\chhdportal\HHDForms\DeansList\documents\FERPAwithholdingInfo.pdf"))
myMesg.From = New MailAddress("csufhhdnews@fullerton.edu", "College of H&HD News, CSUF")
'myMesg.To.Add(New MailAddress("slin@fullerton.edu", "Serena Lin"))
myMesg.To.Add(New MailAddress(rdSendEmail("eEm"), rdSendEmail("FirstName") & " " & rdSendEmail("LastName")))
myMesg.Bcc.Add(New MailAddress("slin@fullerton.edu", "Serena Lin"))
Dim mySmtpClient As SmtpClient = New SmtpClient
'mySmtpClient.Send(myMesg)
myMesg.Dispose()
mySmtpClient.Dispose()
Label1.Text &= rdSendEmail("DLStuId") & ". " & rdSendEmail("eEm") & "<br />"
End While
End If
rdSendEmail.Close()
cmdSendEmail.Dispose()
conn.Close()
Button1.Enabled = False
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Dean's List letter in PDF
DLLetterPDF("Fall2023")
End Sub
Private Sub DistRSVPEmail(ByVal dbstring As String, ByVal filestring As String, ByVal subjectstring As String)
openconnection()
'Dim dbstring As String = "Select * from DeanslistFall2023 WHERE (Semester IS NULL)"
dbstring = "Select * from DeanslistFall2023"
'Dim dbstring As String = "Select * from DeanslistSPFA2021 WHERE (DLRSVP IS NULL) AND (DLStuId BETWEEN 2701 AND 3000)"
'Dim dbstring As String = "Select TOP(3) * from DeansListSample"
Dim cmdSendEmail As SqlCommand = New SqlCommand(dbstring, conn)
Dim rdSendEmail As SqlDataReader = cmdSendEmail.ExecuteReader
If rdSendEmail.HasRows Then
While rdSendEmail.Read
Dim EmailFile As String = Server.MapPath("~/DeansList/documents/" & filestring)
Dim emailcontent As String = File.ReadAllText(EmailFile)
emailcontent = emailcontent.Replace("##stuname##", rdSendEmail("FirstName"))
'emailcontent = emailcontent.Replace("##accesscode##", rdSendEmail("DLAC"))
Dim myMesg As MailMessage = New MailMessage
myMesg.Subject = subjectstring '& " - " & rdSendEmail("FirstName") & " " & rdSendEmail("LastName") & " (" & rdSendEmail("eEmail") & ")"
myMesg.IsBodyHtml = True
myMesg.Body = emailcontent
'myMesg.Attachments.Add(New Attachment("E:\WebApps\chhdportal\HHDForms\DeansList\documents\HHD_Student_Recognition_Invite_2022.pdf"))
myMesg.From = New MailAddress("csufhhdnews@fullerton.edu", "College of H&HD News, CSUF")
'myMesg.To.Add(New MailAddress("slin@fullerton.edu", "Serena Lin"))
myMesg.To.Add(New MailAddress(rdSendEmail("eEmail"), rdSendEmail("FirstName") & " " & rdSendEmail("LastName")))
myMesg.Bcc.Add(New MailAddress("phue@fullerton.edu", "Phong Hue"))
Dim mySmtpClient As SmtpClient = New SmtpClient
'mySmtpClient.Send(myMesg)
myMesg.Dispose()
mySmtpClient.Dispose()
Label1.Text &= rdSendEmail("DLStuId") & ". " & rdSendEmail("FirstName") & " " & rdSendEmail("LastName") & " (" & rdSendEmail("eEmail") & ")<br />"
End While
End If
rdSendEmail.Close()
cmdSendEmail.Dispose()
conn.Close()
End Sub
thanks.