suju_26pro
Well-known member
- Joined
- May 4, 2011
- Messages
- 48
- Programming Experience
- Beginner
Private Sub SendMail(ByVal fromAddress As String, ByVal toAddress As String, ByVal subject As String, ByVal body As String, ByVal smtp As String, ByVal port As String, Optional ByVal attachment As String(), Optional userName As String, Optional password As String) Try Dim Message As New System.Net.Mail.MailMessage(fromAddress, toAddress, subject, body) Dim emailClient As New System.Net.Mail.SmtpClient(smtp, port) If Not userName = "" And Not password = "" Then Dim credantails As New System.Net.NetworkCredential(userName, password) End If If Not attachment Is Nothing Then For Each attach In attachment If Not attach = "" Then Message.Attachments.Add(New Net.Mail.Attachment(attach)) End If Next End If emailClient.Send(Message) Catch ex As Exception End Try End Sub
For Each row As DataGridViewRow In DataGridView1.Rows If Not CType(row.Cells(0), DataGridViewCheckBoxCell).Value = CType(row.Cells(0), DataGridViewCheckBoxCell).TrueValue Then Dim FileName As String = row.Cells(1).Value Dim EmailAddress As String = row.Cells(2).Value ' send the email as usually Dim message As New MailMessage message.To.Add(New MailAddress("recipient email")) message.From = New MailAddress("sender email") message.Subject = "Subject line" message.Body = "Message Body" message.Attachments.Add(New Attachment(FileName)) Dim client As New SmtpClient("localhost") client.Send(message) message.Dispose() client = Nothing End If Next
Imports System.Net.Mail Public Class Form1 Private Sub DataGridView1_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.ColumnIndex = 1 Then If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then DataGridView1.CurrentCell.Value = OpenFileDialog1.FileName End If End If End Sub Private Sub CancelButton_Click(sender As System.Object, e As System.EventArgs) Handles CancelButton.Click Application.Exit() End Sub Private Sub EmailButton_Click(sender As System.Object, e As System.EventArgs) Handles EmailButton.Click For Each row As DataGridViewRow In DataGridView1.Rows If Not CType(row.Cells(0), DataGridViewCheckBoxCell).Value = CType(row.Cells(0), DataGridViewCheckBoxCell).TrueValue Then Dim FileName As String = row.Cells(1).Value Dim EmailAddress As String = row.Cells(2).Value ' send the email as usually Dim message As New MailMessage message.To.Add(New MailAddress("recipient email")) message.From = New MailAddress("sender email") message.Subject = "Subject line" message.Body = "Message Body" message.Attachments.Add(New Attachment(FileName)) Dim client As New SmtpClient("localhost") client.Send(message) message.Dispose() client = Nothing End If Next End Sub End Class
Right, but suju_26pro didn't answer. I had helped suju_26pro with this project on a different issue and he was using a ListView.
Ok then you can probably help him again. However the code above does exactly what he wants!