Click here to Skip to main content
15,911,485 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: problems with setparent in vb .net 2008 Pin
larry11828-Oct-13 5:10
larry11828-Oct-13 5:10 
AnswerRe: problems with setparent in vb .net 2008 Pin
Eddy Vluggen28-Oct-13 8:40
professionalEddy Vluggen28-Oct-13 8:40 
GeneralRe: problems with setparent in vb .net 2008 Pin
larry11828-Oct-13 9:01
larry11828-Oct-13 9:01 
GeneralRe: problems with setparent in vb .net 2008 Pin
Eddy Vluggen29-Oct-13 8:42
professionalEddy Vluggen29-Oct-13 8:42 
GeneralRe: problems with setparent in vb .net 2008 Pin
larry11829-Oct-13 9:09
larry11829-Oct-13 9:09 
QuestionHOW TO READ DATA FROM BCP BARCODE SCANNER Pin
Member 1035533223-Oct-13 6:30
Member 1035533223-Oct-13 6:30 
AnswerRe: HOW TO READ DATA FROM BCP BARCODE SCANNER Pin
Eddy Vluggen23-Oct-13 7:08
professionalEddy Vluggen23-Oct-13 7:08 
GeneralAdvanced Email in VB.NET Pin
Dhanish Balloo22-Oct-13 19:42
Dhanish Balloo22-Oct-13 19:42 
Hi all,

I need to develop a small but rather advanced email app using vb.net
Up to now everything has been going smoothly until my lecturer asked me to include pictures in the email
I successfully managed to include the picture as attachment but he wanted the picture to be included in the email body itself and not as attachment
Now for 1 image I managed to do it by converting the email into html format and sending it
But now the real problem is when the user wishes to include several pictures in the email
How am i to detect the number of pictures and rewrite the equivalent email html??
I am using a richtextbox for the input of text and pictures

What I managed to do up till now is as follows

Imports System.Net.Mail
Imports System.Net.Mime

Public Class Form1
    Dim picturePath As String
    Dim pictureExt As String
    Dim filePath As String = ""

    Private Sub btnSend_Click(sender As System.Object, e As System.EventArgs) Handles btnSend.Click
        Dim smtp As New SmtpClient
        Dim avHtml As AlternateView
        Dim mail As MailMessage = New MailMessage
        Dim htmlBody As String
        Dim pic1 As LinkedResource
        Dim x() As String

        x = txtBody.Text.Split(" ")

        smtp.UseDefaultCredentials = False
        smtp.Credentials = New Net.NetworkCredential("myEmail@yahoo.com", "myPassword")
        smtp.Port = "25"
        smtp.EnableSsl = True
        smtp.Host = "smtp.live.com"

        Try
            htmlBody = "<html> "
            htmlBody = htmlBody & "<body> "

            If Not x(0) = Nothing Then htmlBody = htmlBody & x(0)

            htmlBody = htmlBody & "<br /> "
            htmlBody = htmlBody & "<img src='cid:Pic1'> "
            htmlBody = htmlBody & "<br /> "

            If Not x(1) = Nothing Then htmlBody = htmlBody & x(1)

            htmlBody = htmlBody & "</body> "
            htmlBody = htmlBody & "</html>"

            avHtml = AlternateView.CreateAlternateViewFromString(htmlBody, Nothing, MediaTypeNames.Text.Html)

            Select Case pictureExt
                Case "jpg", "JPG", "jpeg", "JPEG"
                    pic1 = New LinkedResource(picturePath, MediaTypeNames.Image.Jpeg)
                Case "gif", "GIF"
                    pic1 = New LinkedResource(picturePath, MediaTypeNames.Image.Gif)
                Case "tiff", "tif", "TIFF", "TIF"
                    pic1 = New LinkedResource(picturePath, MediaTypeNames.Image.Tiff)
            End Select

            pic1.ContentId = "Pic1"
            avHtml.LinkedResources.Add(pic1)

            mail.From = New MailAddress("myEmail@yahoo.com")
            mail.To.Add(txtTo.Text)
            mail.Subject = txtSubject.Text
            mail.IsBodyHtml = True
            mail.Body = htmlBody
            mail.AlternateViews.Add(avHtml)

            If Not filePath = "" Then mail.Attachments.Add(New System.Net.Mail.Attachment(filePath))

            smtp.Send(mail)

            MsgBox("Email sent!")

            txtBody.Text = ""
            txtSubject.Text = ""
            txtTo.Text = ""
            picturePath = ""
            pictureExt = ""
            filePath = ""
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally

        End Try
    End Sub

    Private Sub btnAddImage_Click(sender As System.Object, e As System.EventArgs) Handles btnAddImage.Click
        Dim openDlg As OpenFileDialog = New OpenFileDialog
        Dim filter As String = openDlg.Filter
        Dim tmp() As String
        Dim img As Image
        Dim orgData

        openDlg.Filter = "Image File (*.tiff;*.jpg;*.gif)|*.tiff;*.jpg;*.gif"
        openDlg.Title = "Open an image file"

        If (openDlg.ShowDialog() = DialogResult.OK) Then
            picturePath = openDlg.FileName

            tmp = picturePath.Split(".")

            pictureExt = tmp(1)

            img = Image.FromFile(picturePath)

            orgData = Clipboard.GetDataObject

            Clipboard.SetImage(img)

            txtBody.Paste()
        End If
    End Sub

    Private Sub btnAddAttachement_Click(sender As System.Object, e As System.EventArgs) Handles btnAddAttachement.Click
        Dim openDlg As OpenFileDialog = New OpenFileDialog

        If (openDlg.ShowDialog() = DialogResult.OK) Then
            filePath = openDlg.FileName
        End If
    End Sub
End Class

AnswerRe: Advanced Email in VB.NET Pin
Eddy Vluggen23-Oct-13 7:00
professionalEddy Vluggen23-Oct-13 7:00 
GeneralRe: Advanced Email in VB.NET Pin
Dhanish Balloo24-Oct-13 0:33
Dhanish Balloo24-Oct-13 0:33 
GeneralRe: Advanced Email in VB.NET Pin
Chris Quinn24-Oct-13 1:42
Chris Quinn24-Oct-13 1:42 
GeneralRe: Advanced Email in VB.NET Pin
Dhanish Balloo24-Oct-13 1:49
Dhanish Balloo24-Oct-13 1:49 
GeneralRe: Advanced Email in VB.NET Pin
Kenneth Haugland24-Oct-13 2:04
mvaKenneth Haugland24-Oct-13 2:04 
AnswerRe: Advanced Email in VB.NET Pin
Eddy Vluggen24-Oct-13 8:25
professionalEddy Vluggen24-Oct-13 8:25 
GeneralRe: Advanced Email in VB.NET Pin
Dhanish Balloo24-Oct-13 19:02
Dhanish Balloo24-Oct-13 19:02 
GeneralRe: Advanced Email in VB.NET Pin
Eddy Vluggen25-Oct-13 12:31
professionalEddy Vluggen25-Oct-13 12:31 
QuestionError displayed when trying to load Dictionary.com in my application Pin
Bitan Galactico Basak22-Oct-13 8:53
Bitan Galactico Basak22-Oct-13 8:53 
AnswerRe: Error displayed when trying to load Dictionary.com in my application Pin
scottgp22-Oct-13 9:15
professionalscottgp22-Oct-13 9:15 
GeneralRe: Error displayed when trying to load Dictionary.com in my application Pin
Bitan Galactico Basak22-Oct-13 9:41
Bitan Galactico Basak22-Oct-13 9:41 
SuggestionRe: Error displayed when trying to load Dictionary.com in my application Pin
Richard Deeming22-Oct-13 9:27
mveRichard Deeming22-Oct-13 9:27 
GeneralRe: Error displayed when trying to load Dictionary.com in my application Pin
thatraja24-Oct-13 3:32
professionalthatraja24-Oct-13 3:32 
AnswerRe: Error displayed when trying to load Dictionary.com in my application Pin
TnTinMn22-Oct-13 13:40
TnTinMn22-Oct-13 13:40 
QuestionCalling Functions in DLLs Pin
SeaWasp122-Oct-13 3:41
SeaWasp122-Oct-13 3:41 
AnswerRe: Calling Functions in DLLs Pin
Simon_Whale22-Oct-13 3:49
Simon_Whale22-Oct-13 3:49 
GeneralRe: Calling Functions in DLLs Pin
SeaWasp122-Oct-13 8:26
SeaWasp122-Oct-13 8:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.