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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed to move from vb 6 to vb.net just don't get the classes 1

Status
Not open for further replies.

russellmunday

Technical User
Jul 24, 2003
87
GB
I for some reason can not understand the classes i am having a real hard time with an application using code ive used in vb 6 lots of times in the past to send email.

Dim olapp
Dim olitm

Set olapp = CreateObject("Outlook.Application")
Set olitm = App.CreateItem(0)
With olitm
.to me@myaddr.com
.subject “subject “
.body “body text “
.Send
Set olApp = Nothing
Set olitm = Nothing
End With
End If

but his code does not work with vb.net the error says I have not declared it. I have read about classes and have a real mental block.
Does anyone have a code example to replace mine here that will explian it for me or know of a site where i can get a simple explanation please.

 
Check this FAQ:
it may help explain classes and instances to you.

As for the code, I just happen to have a chunk available.

Code:
Public Shared Sub EmailInfo(ByVal Message As String, _
                            ByVal Recipients As String, _
                            ByVal Sender As String)
  ' Purpose : Email the Information to the designated recipients.  This routine uses the 
  '           config file to pull the local email server information.
  ' Accepts	: Message    - Verbiage to be added to the body of the email.
  '           Recipients - semicolon separated list of email addresses the message
  '                         will be sent to.
  '           Sender     - Email address of the account sending the message
  ' Returns : Nothing

  Dim objMail As New System.Web.Mail.MailMessage()
  Dim cfgConfig As New ConfigFile()

  ' Assemble Email.
  With objMail
    .To = Recipients
    .From = Sender
    .Subject = CurrentApp & " Log message"
    .Body = Message
    .BodyFormat = Web.Mail.MailFormat.Text
  End With

  System.Web.Mail.SmtpMail.SmtpServer = cfgConfig.GetAppSetting("SMTP Server")
  System.Web.Mail.SmtpMail.Send(objMail)
  Call LogInfo(Message)
End Sub

-Rick

----------------------
 
You can also use Outlook to send Mail, but you need to add a reference to Outlook before you can use it. Once you've done that you can initialise objects such as
Code:
Dim oApp As New Outlook.Application
Dim oNameSpace As Outlook.NameSpace
Dim oItems As Outlook.Items
Dim oMail As Outlook.MailItem
Dim oRecipient As Outlook.Recipient
Dim oFolders As Outlook.Folders
and log in becomes familiar looking
Code:
dim sUserName as String="MyUser"
dim sPassword as String="12345"
oNameSpace.Logon(sUserName, sPassword)




Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top