Mass Email using sql server 2005 in windows form RRS feed

  • Question

  • Hi all,

    I am doing a project on sending mass email. My codes should be able to read contacts/email from the SQL Server 2005 database and send mass email with attachments.

    Below are my codes for sending email. My windows application limitation is that it can only send email from a valid email address to a valid address one at a time with the help of a relay server. Also, it doesn't allow the user to attach attachments and could not read from the sql server database.

    Please give me feedback/suggestions/source codes to help me improve on my project.

    Thank you.

    Best Regards.
    Md Azmil

    Imports System.Net
    Imports System.Net.Mail Public Class Form1 Public Sub SendAnEmail(ByVal MsgFrom As String, ByVal MsgTo As String, ByVal MsgSubject As String, ByVal MsgBody As String) Try ' Pass in the message information to a new MailMessage Dim msg As New Net.Mail.MailMessage(MsgFrom, MsgTo, MsgSubject, MsgBody) ' Create an SmtpClient to send the e-mail Dim mailClient As New SmtpClient("localhost") ' = local machine IP Address ' Use the Windows credentials of the current User mailClient.UseDefaultCredentials = True ' Pass the message to the mail server mailClient.Send(msg) ' Optional user reassurance: MessageBox.Show(String.Format("Message Subject ' {0} ' successfully sent From {1} To {2}", MsgSubject, MsgFrom, MsgTo), "EMail", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information) ' Housekeeping msg.Dispose() Catch ex As FormatException MessageBox.Show(ex.Message & " :Format Exception") Catch ex As SmtpException MessageBox.Show(ex.Message & " :SMTP Exception") End Try End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SendAnEmail(txtTo.Text, txtFrom.Text, txtSubj.Text, txtMsg.Text) End Sub End Class

    Monday, June 29, 2009 8:15 AM