Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to send mail by visual basic ?

how to send mail by visual basic ?

Scheduled Pinned Locked Moved Visual Basic
csharpcomhelptutorial
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Golden Jing
    wrote on last edited by
    #1

    Dear All, I do not know asp or c#. i just use visual basic. now i develop an application in order to send mail with attach file to multiple recipience. I take some sample code from websites for study as well but it still can not. my code is: With Mail .From = New System.Net.Mail.MailAddress(mFrom.Trim, pDisplayName) .To.Add(mTo.Trim) .Priority = pPriority .IsBodyHtml = pIsBodyHtml If mCC <> "" Then .CC.Add(mCC.Trim) If mBCC <> "" Then .Bcc.Add(mBCC.Trim) .Subject = CStr(mSubject).Trim .Body = mBody.Trim .DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure End With Smtp.Host = CStr("mail.company.com") Smtp.Port = 888 Dim myCredential As New System.Net.NetworkCredential("golden.meas", "gggggggggg") Smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis Smtp.Credentials = myCredential Smtp.Send(Mail) End With ================ After i sent i can not know weather it success or not. I test to send to my friend mail but can not know weather is success or not and we do not get. what any sold for this ? And do you have any source code related it ? Thanks for your help... Best regards,

    VB.Net

    P 1 Reply Last reply
    0
    • G Golden Jing

      Dear All, I do not know asp or c#. i just use visual basic. now i develop an application in order to send mail with attach file to multiple recipience. I take some sample code from websites for study as well but it still can not. my code is: With Mail .From = New System.Net.Mail.MailAddress(mFrom.Trim, pDisplayName) .To.Add(mTo.Trim) .Priority = pPriority .IsBodyHtml = pIsBodyHtml If mCC <> "" Then .CC.Add(mCC.Trim) If mBCC <> "" Then .Bcc.Add(mBCC.Trim) .Subject = CStr(mSubject).Trim .Body = mBody.Trim .DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure End With Smtp.Host = CStr("mail.company.com") Smtp.Port = 888 Dim myCredential As New System.Net.NetworkCredential("golden.meas", "gggggggggg") Smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis Smtp.Credentials = myCredential Smtp.Send(Mail) End With ================ After i sent i can not know weather it success or not. I test to send to my friend mail but can not know weather is success or not and we do not get. what any sold for this ? And do you have any source code related it ? Thanks for your help... Best regards,

      VB.Net

      P Offline
      P Offline
      Paramu1973
      wrote on last edited by
      #2

      Have a look ! Just I found in MSDN, Answered by Martin, also it will save the mail message as textfile. Imports System.Net.Mail Imports System.IO Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim mailInstance As MailMessage = New MailMessage("FromMailAdress", "ToMailAdress") Try mailInstance.Subject = "This is mail subject" mailInstance.Body = "This is mail body content" mailInstance.Attachments.Add(New Attachment("filename")) 'Optional Dim mailSenderInstance As SmtpClient = New SmtpClient("smtpHostAdress", 25) '25 is the port of the SMTP host mailSenderInstance.Credentials = New System.Net.NetworkCredential("LoginAccout", "Password") mailSenderInstance.Send(mailInstance) mailInstance.Dispose() 'Please remember to dispose this object Catch ex As Exception MessageBox.Show(ex.Message) Dim sw As StreamWriter = New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myMail.txt") sw.WriteLine(mailInstance.From) sw.WriteLine(mailInstance.To) sw.WriteLine(mailInstance.Subject) sw.WriteLine(mailInstance.Body) sw.WriteLine(mailInstance.Attachments) sw.Close() End Try End Sub :thumbsup:

      G 1 Reply Last reply
      0
      • P Paramu1973

        Have a look ! Just I found in MSDN, Answered by Martin, also it will save the mail message as textfile. Imports System.Net.Mail Imports System.IO Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim mailInstance As MailMessage = New MailMessage("FromMailAdress", "ToMailAdress") Try mailInstance.Subject = "This is mail subject" mailInstance.Body = "This is mail body content" mailInstance.Attachments.Add(New Attachment("filename")) 'Optional Dim mailSenderInstance As SmtpClient = New SmtpClient("smtpHostAdress", 25) '25 is the port of the SMTP host mailSenderInstance.Credentials = New System.Net.NetworkCredential("LoginAccout", "Password") mailSenderInstance.Send(mailInstance) mailInstance.Dispose() 'Please remember to dispose this object Catch ex As Exception MessageBox.Show(ex.Message) Dim sw As StreamWriter = New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myMail.txt") sw.WriteLine(mailInstance.From) sw.WriteLine(mailInstance.To) sw.WriteLine(mailInstance.Subject) sw.WriteLine(mailInstance.Body) sw.WriteLine(mailInstance.Attachments) sw.Close() End Try End Sub :thumbsup:

        G Offline
        G Offline
        Golden Jing
        wrote on last edited by
        #3

        Thanks Paramu, In that source is send to only one mail right ? it seems to me that it has no Cc and Bcc. If I would like to send to multiple recipienceand ,Cc,Bcc and with attach multiple files, what should i do? On the other hand when i test to send it by this code which copy from you: Imports System.Net.Mail Imports System.IO Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim mailInstance As MailMessage = New MailMessage("MyEmailAddress", "RecipienceAddress") Try mailInstance.Subject = Trim(Me.txtSubject.Text) mailInstance.Body = Trim(Me.txtBody.Text) mailInstance.Attachments.Add(New Attachment("D:\11112009204.jpg")) Dim mailSenderInstance As SmtpClient = New SmtpClient("mail.tmic.com.kh", 587) mailSenderInstance.Credentials = New System.Net.NetworkCredential("myLongAccount", "MyPassowrd") mailSenderInstance.Send(mailInstance) mailInstance.Dispose() 'Please remember to dispose this object Catch ex As Exception MessageBox.Show(ex.Message) Dim sw As StreamWriter = New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myMail.txt") sw.WriteLine(mailInstance.From) sw.WriteLine(mailInstance.To) sw.WriteLine(mailInstance.Subject) sw.WriteLine(mailInstance.Body) sw.WriteLine(mailInstance.Attachments) sw.Close() End Try End Sub It got message error that "Syntax error in parameters or arguments. The server response was: Authentication failed: malformed response" what is that problem ?

        VB.Net

        modified on Tuesday, December 8, 2009 9:44 PM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups