Everyone, thank you soooo much for the help! I started this project 1 week
ago, and just finished today. As I alluded to before, I am a VBA guy, trying
to become a VB.NET guy. Everyone's guidance was helpful, but in the end I
just couldn't figure out how the SMTP server stuff worked, and that was the
hangup for me. I eventually got help from a guy in my office. Thanks
Sankalp!!
So, anyway, I want to share the final product, so others can benefit from
this experience. FYI, you need a Gmail account:
Create a Form, and name it 'frmMain'
Create a To TextBox, and name it 'txtTo'
Create a CC TextBox, and name it 'txtCC'
Create a BCC TextBox, and name it 'txtBCC'
Create a Subject TextBox, and name it 'txtSubject'
Create an email Body TextBox, and name it 'txtBody'
Then, create a Send Button, and name it 'btnSend'
This code goes under the Form:
Imports System.Net.Mail
Public Class frmMain
Private _Username As String
Private _Password As String
Public Property UserName() As String
Get
Return _Username
End Get
Set(ByVal value As String)
_Username = value
End Set
End Property
Public Property Password() As String
Get
Return _Password
End Get
Set(ByVal value As String)
_Password = value
End Set
End Property
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSend.Click
'Start by creating a mail message object
Dim MyMailMessage As New MailMessage()
'From requires an instance of the MailAddress type
Dim _from As String = UserName & "@gmail.com"
MyMailMessage.From = New MailAddress(_from)
'To is a collection of MailAddress types
If txtTo.Text <> "" Then
MyMailMessage.To.Add(txtTo.Text)
Else
MessageBox.Show("You need to enter atlest one e-mail address")
End If
If txtBCC.Text <> "" Then
MyMailMessage.Bcc.Add(txtBCC.Text)
End If
If txtCC.Text <> "" Then
MyMailMessage.CC.Add(txtCC.Text)
End If
MyMailMessage.Subject = txtSubject.Text
MyMailMessage.Body = txtBody.Text
'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
' SMTPServer.Credentials = New
System.Net.NetworkCredential("sankalppande", "Bittu1541982")
SMTPServer.Credentials = New System.Net.NetworkCredential(UserName,
Password)
SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
MessageBox.Show("Email Sent")
Catch ex As SmtpException
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Finally...yes, almost done...
Create another Form, and name it 'LoginForm'
Create a UserName TextBox and name it 'UsernameTextBox'
Create a Password TextBox and name it 'PasswordTextBox'
Create a Button named 'Cancel' and one more Button named 'OK'
This code goes under the Form:
Public Class LoginForm
' TODO: Insert code to perform custom authentication using the provided
username and password
' (See
http://go.microsoft.com/fwlink/?LinkId=35339).
' The custom principal can then be attached to the current thread's
principal as follows:
' My.User.CurrentPrincipal = CustomPrincipal
' where CustomPrincipal is the IPrincipal implementation used to perform
authentication.
' Subsequently, My.User will return identity information encapsulated in
the CustomPrincipal object
' such as the username, display name, etc.
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OK.Click
frmMain.UserName = Me.UsernameTextBox.Text
frmMain.Password = Me.PasswordTextBox.Text
frmMain.Show()
Me.Visible = False
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
End Class
HTH,
Ryan---