how can i email document ?

suju_26pro

Well-known member
Joined
May 4, 2011
Messages
48
Programming Experience
Beginner
Thnx a lot Joshdbr, with help u i can however manage to make my application run...thnx a lot .....

Now can u suggest me how can i email the checked document to a specific email id, i want to use pop3 for this, plz provide code if u can ..thnx once again...
 
Last edited by a moderator:
Give this a go:

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



You will probably have to mess with the settings a little, but there's the basic idea.

-Josh
 
Thread split, start new threads for new topics.
 
How Do I mail the multiple document to multiple recepient

Hii Frndz I am just stuck at my academics project.The problem is that i am confused how do achieve the following requiredment,.......
The user will check the file from the checklist box and provide the specific email id to mail that document to that email id.....I just hv no idea how do i achieve this...

for better understanding i had just upload pics ..i want in the same way as it is show in pics....plz help me out....plz provide code ,,as i am new to this approach..waiting eagerly 4 yours helpful advice..plz help me out.....:confused:
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    39 KB · Views: 58
If it's DataGridView then use the following code:


         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
 
Last edited:
thnx 4 your reply , but i cant handle this code ...can u plz provide me with sample application to achieved this...i will be great thnx to u ..i want to hv a better understanding of it , if u provide me a sample application i can explorer its feature..with a code it will take me a long time..plz help me....

:confused:
 
Last edited by a moderator:
It is pretty simple (str8 forward)

1. create a new project
2. add datagridview control to the form1
3. add the three needed columns to the datagridview
4. add the three needed buttons too
4. add openfile dialog to the form
5. paste the following code. Voila!

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
 

Attachments

  • EmailClient.zip
    11.5 KB · Views: 21
I believe that suju_26pro is using a ListView control, not a DataGridView.
 
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!

I don't mean to butt in, I'm sure that your code will work fine. You just might want to change it to use a ListView instead of a DataGridView.
 
thnx for help it does wht i need but one problem ..i hv to click on each cell to load a file in it..wht i want is that i browse a specific folder , select that folder and that will add all pdf file in this view..where i can check which document i hv to email or which nt using checkbox....hope u understand wht i want to say ..thnxxxx
 
Back
Top