Send Email with Attachment Using vb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PleaseHelpMe
    New Member
    • Aug 2008
    • 2

    Send Email with Attachment Using vb

    Any1 can tell me how to go about sending email with attachment in vb programming code. I know SMTP is one option, but I can't seem to get it working. Any other suggestion??

    Thanks in advance
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    smtp as you stated is one option but depending on who your end users are you can also use the office inerop components

    I will have a look later and try to find / work out some working email code for the smtp , I believe that you have to send the email as html and convert the file to a mime encodement somehow.

    Comment

    • PleaseHelpMe
      New Member
      • Aug 2008
      • 2

      #3
      Originally posted by jg007
      smtp as you stated is one option but depending on who your end users are you can also use the office inerop components

      I will have a look later and try to find / work out some working email code for the smtp , I believe that you have to send the email as html and convert the file to a mime encodement somehow.
      here is my code( i got 3 sets of code) , but all 3 is not working, and i don't know where went wrong, Please Help! Thanks in advance

      ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''
      'Web.Mail.SmtpM ail.SmtpServer = "user1"
      'Dim msg As New Web.Mail.MailMe ssage

      'msg.From = "weijie@adm in"
      'msg.To = "weijie1412@hot mail.com"
      'msg.Subject = "testing"
      'msg.Body = "hello first email"
      'msg.BodyFormat = Web.Mail.MailFo rmat.Text

      'Web.Mail.SmtpM ail.Send(msg)

      'MsgBox("Yea")
      ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '''''
      'Dim msg As System.Web.Mail .MailMessage
      'Dim smtp As System.Web.Mail .SmtpMail
      'Dim att As System.Web.Mail .MailAttachment

      'msg.To = "weijie1412@hot mail.com"
      'msg.From = "weijie1412@gma il.com"
      'msg.BodyFormat = MailFormat.Text
      'msg.Body = " testing, Please work pls "
      'msg.Cc = " Cc: Testing, Please Work "
      'msg.Subject = "Testing purpose"


      'smtp.Send(msg)

      ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''
      'Dim message As System.Net.Mail .MailMessage
      'Dim smtp As New System.Net.Mail .SmtpClient("sm tp.gmail.com", 587)

      ''Dim attach As System.Net.Mail .Attachment
      'Dim sFrom As String, sTo As String, sSsub As String, sMsg As String
      ''Dim sFile As String

      'sFrom = "user1.edel@gma il.com"
      'sTo = "weijie1412@hot mail.com"
      ''sFile = "D:\\j\\j5\\h\\ tgk\\net\\eml1\ \e2\\emlcmds.tx t"
      'sSsub = "t w"
      'sMsg = "a"

      'message = New System.Net.Mail .MailMessage(sF rom, sTo, sSsub, sMsg)

      ''If My.Computer.Fil eSystem.FileExi sts(sFile) Then
      '' attach = New System.Net.Mail .Attachment(sFi le)
      '' message.Attachm ents.Add(attach )
      ''End If

      'smtp.EnableSsl = True
      'smtp.Credentia ls = New System.Net.Netw orkCredential(" user1.edel@gmai l.com", "pwd")

      'Try
      ' smtp.Send(messa ge)
      ' Console.WriteLi ne("Sent")
      'Catch exc As Net.Mail.SmtpEx ception
      ' Console.WriteLi ne(exc.StatusCo de.ToString)
      'End Try

      'tbxEmail.Text = ""

      ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''

      Comment

      • jg007
        Contributor
        • Mar 2008
        • 283

        #4
        if I have a chance I will look through the code and try to see what is wrong but meanwhile try looking at this tutorial -

        Comment

        • rpicilli
          New Member
          • Aug 2008
          • 77

          #5
          Hi

          THis is the easy way to do that. Put this code insite a Buttom Click event

          [CODE]

          Dim mySmtp As New System.Net.Mail .SmtpClient
          mySmtp.Host = "192.168.2. 1" 'or your correct smtp server name i.e. "smtp.terra.com "
          Try
          mySmtp.Send("rp icilli@terra.co m.br", "toyou@docstibr asil.com.br", "Teste com .NET", "Hi there")
          Catch ex As Exception
          MessageBox.Show (ex.Message)
          End Try

          /[CODE]


          I hope this help

          Comment

          Working...