[Guide] Sending Email and sending attachments menu

User Tag List

Results 1 to 14 of 14
  1. #1
    Murdok's Avatar Member
    Reputation
    34
    Join Date
    Oct 2007
    Posts
    69
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Guide] Sending Email and sending attachments

    Thought i would show you how to send emails using visual Basic

    i know theres a guide for vb.net but not seen one for vb6

    Code:
        On Error Resume Next
        
        Set objnet = CreateObject("WScript.NetWork")
        
        Set oSMTPSession = CreateObject("OSSMTP.SMTPSession")
    
        With oSMTPSession
         .MailFrom = ""
         .SendTo = ""
         .Server = ""
         .Port = 25
         .MessageSubject = ""
         .MessageText = ""
         .SendEmail
        End With
        Set oSMTPSession = Nothing
    .MailFrom = "" 'can be a real email address or just anything, also can = a textbox for variable or any object which can hold text
    .SendTo = "" 'Has to be real ofcourse
    .Server = "" 'SMTP server of who your sending it too
    .Port = 25 'Port normaly 25
    .MessageSubject = "" 'Subject of Email
    .MessageText = "" 'Email text

    all these can = text1.text for example


    now for adding attackments

    General
    Code:
    Dim filename As String
    Dim intCounter As Integer
    command button to Send
    Code:
        On Error Resume Next
        
        Set objnet = CreateObject("WScript.NetWork")
        
        Set oSMTPSession = CreateObject("OSSMTP.SMTPSession")
    
        With oSMTPSession
         .MailFrom = txtFrom.Text
         .SendTo = txtEmail.Text
         .Server = txtServer.Text
         .Port = 25
         .MessageSubject = txtSubject.Text
         .MessageText = txtText.Text
    
     If intCounter >= "1" Then
     Else
      GoTo send
     End If
              
         'adding attachment
         Set oAttachment = CreateObject("OSSMTP.Attachment")
         oAttachment.FilePath = filename
         oAttachment.AttachmentName = txtAname.Text
         oAttachment.ContentType = "application/xml"
         oAttachment.ContentTransferEncoding = 1
         .Attachments.Add oAttachment
    send:
         .SendEmail
        End With
        Set oSMTPSession = Nothing
    The if statement is there for when an attachment is not there becuase without it, it will only send if you add an attachment


    Set oAttachment = CreateObject("OSSMTP.Attachment")
    oAttachment.FilePath = filename 'location o0f attachment
    oAttachment.AttachmentName = "" 'name of attachment
    oAttachment.ContentType = "application/xml"
    oAttachment.ContentTransferEncoding = 1
    .Attachments.Add oAttachment

    for adding an attachment i would add a commondialog1 which can be done by

    Project -> components -> Microsoft common dialog control 6.0

    then adding it to the form

    then

    Command button for adding attachment

    Code:
    commondialog1.showopen
    filename = CommonDialog1.filename
    you might want to add a if statment to check if filename = ""

    also in that command button you need

    Code:
    intcounter = intcounter + 1
    Here is a simple program i made

    Download:

    MEGAUPLOAD - The leading online storage and file delivery service

    Virus Scan:

    Virustotal. MD5: a29cc036331c6eff9b5fa75f9ff02bb1

    [Guide] Sending Email and sending attachments
  2. #2
    Zeroi9's Avatar Banned
    Reputation
    286
    Join Date
    Aug 2008
    Posts
    911
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    name "oSMTPSession" is not declared.

    Please help!

  3. #3
    Murdok's Avatar Member
    Reputation
    34
    Join Date
    Oct 2007
    Posts
    69
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing where it says

    oSMTPSession

    to something like

    SMTPSession

    see if that helps

  4. #4
    Zeroi9's Avatar Banned
    Reputation
    286
    Join Date
    Aug 2008
    Posts
    911
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Murdok View Post
    Try changing where it says

    oSMTPSession

    to something like

    SMTPSession

    see if that helps
    Same :'[ Wil give 2x+Rep to you and write your name in credz if you fix this.

  5. #5
    Murdok's Avatar Member
    Reputation
    34
    Join Date
    Oct 2007
    Posts
    69
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can i have a look at the code you have atm for the email part?

    and are you using vb6?

  6. #6
    Zeroi9's Avatar Banned
    Reputation
    286
    Join Date
    Aug 2008
    Posts
    911
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Murdok View Post
    can i have a look at the code you have atm for the email part?

    and are you using vb6?

    VB8 should LOVE if you cold fix the code for VB 8 !!!
    and the code is copied from you ,exept everthing is directed to Textboxes.

  7. #7
    Murdok's Avatar Member
    Reputation
    34
    Join Date
    Oct 2007
    Posts
    69
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here this should work

    Code:
    Dim oMsg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage() 
    
    oMsg.From = "" 
    oMsg.To = "" 
    oMsg.Subject = "" 
    oMsg.Body = "" 
    Dim oAttch As MailAttachment = New MailAttachment("")  
    oMsg.Attachments.Add(oAttch) 
    SmtpMail.Send(oMsg)

  8. #8
    Zeroi9's Avatar Banned
    Reputation
    286
    Join Date
    Aug 2008
    Posts
    911
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Murdok View Post
    Here this should work

    Code:
    Dim oMsg As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage() 
    
    oMsg.From = "" 
    oMsg.To = "" 
    oMsg.Subject = "" 
    oMsg.Body = "" 
    Dim oAttch As MailAttachment = New MailAttachment("")  
    oMsg.Attachments.Add(oAttch) 
    SmtpMail.Send(oMsg)
    Did not work ='[
    getting that isnt valid

  9. #9
    Neth'zul's Avatar Banned
    Reputation
    204
    Join Date
    Nov 2007
    Posts
    887
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dim mail As New MailMessage()
    Dim SmtpServer As New SmtpClient
    SmtpServer.Credentials = New Net.NetworkCredential("username", "password")
    SmtpServer.Port = 587
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.EnableSsl = True
    mail.To.Add("your_target@gmail.com")
    mail.From = New MailAddress("username@gmail.com")
    mail.Subject = "My E-Mail from my Visual Basic Program"
    mail.Body = " Hello. Do you think this is nice? and btw. EmiloZ helped me to make it "
    SmtpServer.Send(mail)



    This is from Emiloz's post, give rep to him. I think this is VB8
    EDIT: Also dont forget to do this
    "Imports System.Net.Mail"
    Last edited by Neth'zul; 11-05-2008 at 06:56 PM.

  10. #10
    Zurkei's Avatar Contributor

    Reputation
    91
    Join Date
    Apr 2007
    Posts
    405
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Neth'zul View Post
    Dim mail As New MailMessage()
    Dim SmtpServer As New SmtpClient
    SmtpServer.Credentials = New Net.NetworkCredential("username", "password")
    SmtpServer.Port = 587
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.EnableSsl = True
    mail.To.Add("your_target@gmail.com")
    mail.From = New MailAddress("username@gmail.com")
    mail.Subject = "My E-Mail from my Visual Basic Program"
    mail.Body = " Hello. Do you think this is nice? and btw. EmiloZ helped me to make it "
    SmtpServer.Send(mail)



    This is from Emiloz's post, give rep to him. I think this is VB8
    EDIT: Also dont forget to do this
    "Imports System.Net.Mail"
    He used a similar code but not the same.

  11. #11
    Neth'zul's Avatar Banned
    Reputation
    204
    Join Date
    Nov 2007
    Posts
    887
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, but you HAVE to remember to Import System.Net.Mail, it is very important or it will not work!

  12. #12
    Zurkei's Avatar Contributor

    Reputation
    91
    Join Date
    Apr 2007
    Posts
    405
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Neth'zul View Post
    Yeah, but you HAVE to remember to Import System.Net.Mail, it is very important or it will not work!
    I understand that but I just wanted to state that it was not the same code and only looked similar so there needed to be no credits given to him.

  13. #13
    Neth'zul's Avatar Banned
    Reputation
    204
    Join Date
    Nov 2007
    Posts
    887
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, then I guess my only point is he forgot to import lol XD

  14. #14
    Zeroi9's Avatar Banned
    Reputation
    286
    Join Date
    Aug 2008
    Posts
    911
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Neth'zul View Post
    Dim mail As New MailMessage()
    Dim SmtpServer As New SmtpClient
    SmtpServer.Credentials = New Net.NetworkCredential("username", "password")
    SmtpServer.Port = 587
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.EnableSsl = True
    mail.To.Add("your_target@gmail.com")
    mail.From = New MailAddress("username@gmail.com")
    mail.Subject = "My E-Mail from my Visual Basic Program"
    mail.Body = " Hello. Do you think this is nice? and btw. EmiloZ helped me to make it "
    SmtpServer.Send(mail)



    This is from Emiloz's post, give rep to him. I think this is VB8
    EDIT: Also dont forget to do this
    "Imports System.Net.Mail"

    Uhm I knew that already, its easy. Gratz alot on that "sarcasm" I need FakeMaielr.
    Last edited by Zeroi9; 11-06-2008 at 03:58 PM.

Similar Threads

  1. "A priest's guide to complaining" and YOU
    By Alkhara Majere in forum World of Warcraft Guides
    Replies: 5
    Last Post: 03-21-2007, 06:49 PM
  2. A Guide to Aldor and Scryer Rep Building
    By Alkhara Majere in forum World of Warcraft Guides
    Replies: 6
    Last Post: 02-27-2007, 03:40 PM
  3. [Guide] Alchemy Potions (And where to get)
    By chaosrevenge in forum World of Warcraft Guides
    Replies: 0
    Last Post: 06-11-2006, 01:02 PM
All times are GMT -5. The time now is 02:23 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search