Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending email with SMTP 1

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
Hello, what reference ro componetn shoudl I include with my VB project to use SMTP like the this:

Smtp1.Message.To.Add "you@test.com" ' Specify the recipient
'Smtp1.Message.From = "me@test.com" ' Specify the sender
'Smtp1.Message.Subject = "Test Message" ' Specify the subject
'Smtp1.Message.Text = "This is a test." ' Add message body
'Smtp1.Message.AddAttachment m_szConfirmFileName ' Add attachment
'Smtp1.Login "mail.dart.com" ' Start the mail session
'Smtp1.send ' Send message
'Smtp1.Logout ' End session

thanks a lot!!!
 
You need a SMTP component.

Now which one will depends on what control was used on the program using that bit of code.

It looks like DART by PowerTCP, but it may not be that one.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Guys! Is there SMTP component that comes with VB? I do not want any third party

thanks
 
Well, you can just use CDO if you have Windows 2000 or later:
Code:
Option Explicit 
'Project requires a reference to: 
' "Microsoft CDO for Windows 2000 Library" 

Dim objMessage As New CDO.Message 

Sub Configure(ByVal strServer As String) 
    'Configure for your SMTP server. 
     
    With objMessage.Configuration.Fields 
      .Item(cdoSendUsingMethod) = cdoSendUsingPort 
      .Item(cdoSMTPUseSSL) = False 
      .Item(cdoSMTPServer) = strServer 
      .Item(cdoSMTPServerPort) = 25 
      .Item(cdoSMTPConnectionTimeout) = 60 
      .Item(cdoSMTPAuthenticate) = cdoAnonymous 
      .Update 
    End With 
End Sub 

Sub SendEmail(ByVal strSubj As String, _ 
              ByVal strFrom As String, _ 
              ByVal strTo As String, _ 
              ByVal strText As String) 
    With objMessage 
      .Subject = strSubj 
      .From = strFrom 
      .To = strTo 
      .TextBody = strText 
     
      .Send 
    End With 
End Sub 

Sub Main() 
    Configure "mail.mymail.com" 
    On Error Resume Next 
    SendEmail "Example CDO message", _ 
              """Bill Williams"" <billw@mymail.com>", _ 
              """Robert Finkbeinder"" <Bob@bob.com>", _ 
              "Hello Bob, this is an automated message" & _ 
              " from Bill," & vbNewLine & _ 
              "sent via CDO." 
    If Err.Number = 0 Then 
      MsgBox "Complete!" 
    Else 
      MsgBox "Error &H" & Hex(Err.Number) & vbNewLine & _ 
             Err.Description 
    End If 
End Sub
 
>Is there SMTP component that comes with VB?
>No there isn't,

Well, as Dilettante illustrates, whilst VB doesn't come with a pure SMTP component, every OS from W2K onwards does - W2K, XP, W2K3 (depending on what you have installed, the library may be called Microsoft CDO for Exchange 2000 instead of Microsoft CDO for Windows 2000; the former is a superset of the latter)
 
The MAPI controls require that you have to have had a MAPI client installed* (to provide a MAPI profile, including such info as where your Exchange Server is; if you ain't got a server then the MAPI controls won't help you). Furthermore, they are fairly restricted, being based on the somewhat ancient Simple MAPI


* OK, not quite true. The requirement is that enough has been installed to provide a MAPI profile (which provides the necessary ifo to create a Session). The easiest way to do this is by installing something like Outlook, but MS do provide downloadable tools that just generate MAPI profiles that will work with the MAPI controls
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top