Results 1 to 9 of 9

Thread: email without the using of Outlook objects

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455

    email without the using of Outlook objects

    Dear VB users,

    Is there any possibility to send an email without using the outlook objects?
    If yes, can someone give source code.

    Nice regards,

    Michelle.

  2. #2

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Add MAPI Control to your form then:

    VB Code:
    1. '*******************************************************************************
    2. ' SENDMESSAGETHRUEXPRESS (SUB)
    3. '
    4. ' DESCRIPTION:
    5. ' ACTUALLY SEND THE EMAIL MESSAGE THRU EXPRESS
    6. '*******************************************************************************
    7.  
    8. Sub SENDMESSAGETHRUEXPRESS(DisplayMsg As Boolean, Optional AttachmentPath)
    9.    
    10.     MAPISession1.SignOn
    11.    
    12.     With Me.MAPIMessages1
    13.        
    14.         .SessionID = MAPISession1.SessionID
    15.        
    16.         .MsgIndex = -1
    17.        
    18.         .Compose
    19.        
    20.         .MsgSubject = Me.txtSubject
    21.        
    22.         .RecipType = mapToList
    23.        
    24.         .RecipDisplayName = Me.txtAddressTO
    25.        
    26.         .RecipAddress = Me.txtAddressTO
    27.        
    28.         ' SHOW THE ADDRESS BOOK WITH THE SELECTED RECIPIENT(S)
    29.        
    30.         ' 0=NO EDIT FIELDS, 1=TO, 2=(TO AND CC), 3=(TO, CC AND BLIND CC),
    31.         ' 4=ONLY THOSE SUPPORTED BY MESSAGING SYSTEM WILL BE SHOWN
    32.        
    33.         .AddressEditFieldCount = 1
    34.        
    35.         .MsgNoteText = Me.txtMsg
    36.        
    37.         ' ADD ATTACHMENT FILE IF THE LABEL CONTAINS A SELECTED FILE
    38.        
    39.         If Len(Me.lblAttachment.Caption) > 0 And Me.lblAttachment.Caption > " " Then
    40.            
    41.             .AttachmentPosition = 0
    42.            
    43.             .AttachmentName = lblAttachment
    44.            
    45.             .AttachmentPathName = lblAttachment
    46.            
    47.             .AttachmentType = mapEOLE
    48.            
    49.         End If
    50.        
    51.         ' SEND THE EMAIL
    52.        
    53.         .Send
    54.        
    55.     End With
    56.    
    57.     MAPISession1.SignOff
    58.    
    59. End Sub
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242
    put these objects on your form:
    a textbox for the from emails address ( can be left out, but edit the code to say who it is from)
    a textbox for the main body of the message (can be edited just like above.
    a command button called cmdsend
    a command button called cmdexit
    a label called lblstatus
    a winsock control called Winsock1
    a timer control called Timer1
    VB Code:
    1. Private Sub cmdSend_Click()
    2. Subject = 'the subject here
    3. 'FILL UP OUR EMAIL STRUCTURE
    4. With Myemail
    5.     .From = 'the from email address here
    6.     .Subject = Subject
    7.     .To = myemailaddress
    8.     .Msg = 'The Main body of message here
    9. End With
    10.  
    11. 'NOW WE SEND IT
    12.     cmdSend.Enabled = False
    13.     lblStatus.Caption = "Connecting..."
    14.     Winsock1.Connect Myemail.SMTP, "25"     'Connect to server
    15.    
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.  
    20. myappname = 'the application name here
    21.  
    22. myemailaddress = 'The Email address to send to here
    23.  
    24. With Myemail
    25.     .Format = "plain;"
    26.     .SMTP = "mail.hotmail.com" ' you might want to find a different server, this is the only one i can find, but it can only send to hotmail addresses.
    27. End With
    28.  
    29. End Sub
    30.  
    31. Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    32.     If Not Number = sckSuccess Then
    33.         MsgBox Description          'Display error
    34.         Timer1.Enabled = False
    35.         CloseConn True
    36.     End If
    37. End Sub
    38.  
    39.  
    40.  
    41. Private Sub Winsock1_DataArrival _
    42. (ByVal bytesTotal As Long)
    43.     Dim data As String
    44.     Winsock1.GetData data, vbString
    45.     'Add data arrived data to the already arrived data
    46.     inData = inData + data
    47.     'Wait till a line is recieved (with CR LF in the end)
    48.     If StrComp(Right$(inData, 2), vbCrLf) = 0 Then DataAvailable = True
    49. End Sub
    50. Private Sub Winsock1_Connect()
    51.     lblStatus.Caption = "Connected"
    52.     timer = 0
    53.     Timer1.Enabled = True
    54.     While Not DataAvailable         'Wait for reply
    55.         If Winsock1.State = sckClosed Then Exit Sub
    56.         DoEvents
    57.     Wend
    58.     Timer1.Enabled = False
    59.    
    60.     Dim reply As String
    61.     Dim tmp() As String
    62.     reply = inData
    63.     inData = ""
    64.     DataAvailable = False
    65.     tmp = Split(reply, " ")
    66.     If Not Val(tmp(0)) = 220 Then           'Error occured
    67.         MsgBox "Server returned the following error:" + vbCrLf + reply
    68.         CloseConn False
    69.         Exit Sub
    70.     End If
    71.     lblStatus.Caption = "Receiving Welcome Message"
    72.     'Start the process
    73.     Winsock1.SendData "HELO " + Winsock1.LocalHostName + vbCrLf
    74.     DoEvents
    75.     timer = 0
    76.     Timer1.Enabled = True
    77.     While Not DataAvailable         'Wait for reply
    78.         If Winsock1.State = sckClosed Then Exit Sub
    79.         DoEvents
    80.     Wend
    81.     Timer1.Enabled = False
    82.     reply = inData
    83.     inData = ""
    84.     DataAvailable = False
    85.     tmp = Split(reply, " ")
    86.     If Not Val(tmp(0)) = 250 Then
    87.         MsgBox "Server returned the following error:" + vbCrLf + reply
    88.         CloseConn False
    89.         Exit Sub
    90.     End If
    91.     'Send MAIL FROM
    92.     Winsock1.SendData "MAIL FROM:<" + Myemail.From + ">" + vbCrLf
    93.     DoEvents
    94.     timer = 0
    95.     Timer1.Enabled = True
    96.     While Not DataAvailable         'Wait for reply
    97.         If Winsock1.State = sckClosed Then Exit Sub
    98.         DoEvents
    99.     Wend
    100.     Timer1.Enabled = False
    101.     reply = inData
    102.     inData = ""
    103.     DataAvailable = False
    104.     tmp = Split(reply, " ")
    105.     If Not Val(tmp(0)) = 250 Then
    106.         MsgBox "Server returned the following error:" + vbCrLf + reply
    107.         CloseConn True
    108.         Exit Sub
    109.     End If
    110.     'Send RCPT TO
    111.     Winsock1.SendData "RCPT TO:<" + Myemail.To + ">" + vbCrLf
    112.     DoEvents
    113.     timer = 0
    114.     Timer1.Enabled = True
    115.     While Not DataAvailable         'Wait for reply
    116.         If Winsock1.State = sckClosed Then Exit Sub
    117.         DoEvents
    118.     Wend
    119.     Timer1.Enabled = False
    120.     reply = inData
    121.     inData = ""
    122.     DataAvailable = False
    123.     tmp = Split(reply, " ")
    124.     If Not Val(tmp(0)) = 250 Then
    125.         MsgBox "Server returned the following error:" + vbCrLf + reply
    126.         CloseConn True
    127.         Exit Sub
    128.     End If
    129.     'Send DATA
    130.     DoEvents
    131.     Winsock1.SendData "DATA" + vbCrLf
    132.     DoEvents
    133.     timer = 0
    134.     Timer1.Enabled = True
    135.     While Not DataAvailable         'Wait for reply
    136.         If Winsock1.State = sckClosed Then Exit Sub
    137.         DoEvents
    138.     Wend
    139.     Timer1.Enabled = False
    140.     reply = inData
    141.     inData = ""
    142.     DataAvailable = False
    143.     tmp = Split(reply, " ")
    144.     If Not Val(tmp(0)) = 354 Then
    145.         MsgBox "Server returned the following error:" + vbCrLf + reply
    146.         CloseConn False
    147.         Exit Sub
    148.     End If
    149.     lblStatus.Caption = "Sending Mail . . ."
    150.    
    151.    
    152.     'Send the E-Mail
    153.     Winsock1.SendData "From: <" + Myemail.From + ">" + vbCrLf + _
    154.                       "To: " + Myemail.To + vbCrLf + _
    155.                       "Subject: " + Myemail.Subject + vbCrLf + _
    156.                       "X-Mailer: Gmcd'sBugReport V1" + vbCrLf + _
    157.                       "Mime-Version: 1.0" + vbCrLf + _
    158.                       "Content-Type: text/" + Myemail.Format + vbTab + "charset=us-ascii" + vbCrLf + vbCrLf + _
    159.                       txtMessage.Text
    160.     Winsock1.SendData vbCrLf + "." + vbCrLf
    161.    
    162.    
    163.     DoEvents
    164.     timer = 0
    165.     Timer1.Enabled = True
    166.     While Not DataAvailable             'Wait for reply
    167.         If Winsock1.State = sckClosed Then Exit Sub
    168.         DoEvents
    169.     Wend
    170.     Timer1.Enabled = False
    171.     reply = inData
    172.     inData = ""
    173.     DataAvailable = False
    174.     tmp = Split(reply, " ")
    175.     If Not Val(tmp(0)) = 250 Then               'Error occured
    176.         MsgBox "Server returned the following error:" + vbCrLf + reply
    177.         CloseConn False
    178.         Exit Sub
    179.     End If
    180.     Winsock1.SendData "QUIT"
    181.     MsgBox "Report Sent Successfully", vbInformation, "Done"
    182.     CloseConn False
    183. End Sub
    184.  
    185. Private Sub Timer1_Timer()
    186.     timer = timer + 1
    187.     If timer = TIME_OUT Then
    188.         CloseConn True              'Disconnect if timed out
    189.         MsgBox "Could not connect to host " + Myemail.SMTP + vbCrLf + "Operation timed out"
    190.         Timer1.Enabled = False
    191.     End If
    192. End Sub
    193. Private Sub CloseConn(Err As Boolean)
    194. 'Close Connection & enable contrls
    195.     Winsock1.Close
    196.     lblStatus.Caption = "Send"
    197.     cmdSend.Enabled = True
    198. End Sub
    Lpeek

  5. #5

  6. #6
    New Member
    Join Date
    Nov 2003
    Location
    noida
    Posts
    5
    wat type of object MyEmail is???
    Amazing..

  7. #7
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    It's probably a UDT with all the properties of an e-mail message.
    Don't anthropomorphize computers -- they hate it

  8. #8
    Lively Member
    Join Date
    Jun 2002
    Location
    Coming to a keyboard near you.
    Posts
    79
    You could also use OSSMTP.dll.

    http://www.ostrosoft.com/smtp_component.asp
    Tenebrosity
    "But the plans were on display ..."
    "On display? I eventually had to go down to the cellar to find them, With a torch."
    "That's the display department. The lights had probably gone out."
    "So had the stairs."
    "But look, you found the notice didn't you?"
    "Yes," said Arthur, "yes I did. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard."

  9. #9
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    do a search for CDONTS ... the easiest ...

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