Site Wide Message: (current site time 9/9/2010 9:24:43 PM EDT)
- We want your input! One of our sponsors wants to know your opinion about development related issues. Click here to tell us what you think.
- Are you an emerging/young developer (aged 18-30)? If so, would you like the chance to affect future developer tools and products?
If so, then click here to give your feedback. |
'Ask the .Net Pros Discussion Forum
You are in:
Discussion Home | programming
| Next [Next] Automatic mailing using Vb as smtp server gmail
Next [Next] Automatic mailing using Vb as smtp server gmail
|
Message: |
Hi i completed sending mail automatically. but i have an issue bothering me.. i am using gmail as my smtp server and database as access.i am able to send mails but when i give a wrong address it is redirecting to my mail stating failure of delivery but i want that to be displyed on the console once i send the mail and also if net connection is not available i want it to show network connection is not available..please help .. here is the code so far
Dim ds As New DataSet Private Sub FDaily_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'This procedure overrides the first procedure and accepts a single 'string for the recipient and file attachement ds = GetdatafromAccess() End Sub Private Function GetdatafromAccess() As DataSet Dim con As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim sbmail As New StringBuilder Try con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath() + "\DB\details.mdb" + ";") con.Open() cmd = New OleDbCommand("select * from maildetails where flag=0", con) dr = cmd.ExecuteReader While dr.Read() Try Dim MailMsg As New MailMessage() MailMsg.Subject = "Test Mail" MailMsg.From = New MailAddress("anub96@gmail.com") MailMsg.To.Add(dr("mail_id".ToString)) MailMsg.Body = sbmail.ToString '" Hi " & vbCrLf & vbCrLf & vbCrLf & "How are you?" & vbCrLf & vbCrLf & vbCrLf & "regards" MailMsg.Priority = MailPriority.High 'MailMsg.IsBodyHtml = False MailMsg.IsBodyHtml = True Dim MsgAttach As New Attachment(Application.StartupPath() + "\Upload\Sample.xml") MailMsg.Attachments.Add(MsgAttach) Dim SmtpMail As New SmtpClient("smtp.gmail.com") SmtpMail.Port = 587 SmtpMail.Credentials = New System.Net.NetworkCredential("anub96", "capricorn") SmtpMail.EnableSsl = True 'SmtpMail.Host = "127.0.0.1" SmtpMail.Send(MailMsg) updateflag(dr("ID")) Catch ex As Exception MsgBox(ex.Message) Me.Close() End Try End While Catch ex As Exception MsgBox(ex.Message) Finally 'dr.Close() If con.State = ConnectionState.Open Then con.Close() End Try Me.Close() Return ds End Function Private Function updateflag(ByVal id As String) As Boolean Dim cn As OleDbConnection Dim cmd As OleDbCommand cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath() + "\DB\details.mdb" + ";") 'provider to be used when working with access database Try cn.Open() cmd = New OleDbCommand("update maildetails set flag=1 where ID=" + id.ToString, cn) Dim res As Integer res = cmd.ExecuteNonQuery() If res > 0 Then Return True Else Return False End If Catch ex As Exception Finally ' dr.Close() 'If cn.State = ConnectionState.Open Then cn.Close() End Try End Function End Class
Thanks in advance
|
To reply, please login using the link on the upper left hand corner of the screen.
|
|