Results 1 to 13 of 13

Thread: [RESOLVED} - VB 2010 - help for *.docx as attachment in System.Net.Mail?

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2017
    Posts
    38

    [RESOLVED} - VB 2010 - help for *.docx as attachment in System.Net.Mail?

    Hi, friends! can you help me, please?

    I am developing a emall program that sends emails with attached documents. The documents are of the type: jpg and pdf.

    But I'd like to send docx-type files. However, there is no type of MediatypeName that matches the docx format. The office does not work with rtf files. I've already tried using the media type "Octet", but the file gets corrupted. Below is my code about send e-mails and attachments.

    Code:
      Dim IMG As LinkedResource
    
        Private Sub btnsendemail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsendemail.Click
    
            If listboxdoc.SelectedIndex >= 0 Then
    
    
    
                If txtboxemaildestinatario.Text.Length > 0 Then
                    Dim myfilespath As String = listboxclients.SelectedItem.ToString()
                   
                    txtboxhtmlemail.Text = "Hi! document attached. Best Regards."
    
    
                    Dim MyHTML As String = txtboxhtmlemail.Text
    
                    Dim typeHTML As AlternateView = AlternateView.CreateAlternateViewFromString(MyHTML, Nothing, System.Net.Mime.MediaTypeNames.Text.Html)
    
                    Try
    
                        If listboxdoc.SelectedItem.ToString().Contains(".jpg") Then
                            IMG = New LinkedResource(Application.StartupPath + "\" + myfilespath + "\docs\" + listboxdoc.SelectedItem.ToString(), System.Net.Mime.MediaTypeNames.Image.Jpeg)
    
                        End If
    
                        If listboxdoc.SelectedItem.ToString().Contains(".pdf") Then
                                                    IMG = New LinkedResource(Application.StartupPath + "\" + myfilespath + "\docs\" + listboxdoc.SelectedItem.ToString(), System.Net.Mime.MediaTypeNames.Image.Jpeg)
    
                        End If
    
    
    
                        IMG.ContentId = "Files"
                        
    
                      
    
                        Dim messages As MailMessage = New MailMessage 
                      
    
                        messages.AlternateViews.Add(typeHTML) 
    
                        messages.From = New MailAddress("[email protected]") 
                        messages.To.Add(txtboxemaildestiny.Text) 
                        messages.Subject = "documents from " + listboxclients.SelectedItem.ToString() 
    
                           typeHTML.LinkedResources.Add(IMG) 
                       
                        Dim MISMT As SmtpClient = New SmtpClient("SMTP.GMAIL.COM") 
                        MISMT.EnableSsl = True 
                        MISMT.Port = "587"
                        MISMT.Credentials = New Net.NetworkCredential("blahblahblah", "blahblahblah") 
    
                        MISMT.Send(messages) 
                        MsgBox("Message sent!", MsgBoxStyle.Information)
                     Catch ex As Exception
                        MsgBox(ex.Message)
    
                    End Try
    
                Else
                    MsgBox("Please, insert destiny e-mail.", MsgBoxStyle.Exclamation)
    
                End If
            Else
                MsgBox("Please, select a document.", MsgBoxStyle.Exclamation)
            End If
        End Sub

    So, friends, how can I send attachments in docx format? do I need to use another newer version of Visual Studio? if this is a solution, I will unfortunately not be able to complete my program. Because I'm working on a machine that uses Windows 7 64 bit. Versions after VS 2010 do not work well here. Please help me.

    Thank you all in advance.
    Last edited by vbnewbieuser; Jun 17th, 2019 at 12:40 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width