W7, VS2010, .NET4, and SMTP

Hi, all.

I've been out of the VB loop for a few years, and WOW... Anyway, it took me an hour to find that i couldn't find it in the help file, so I figured I'd ask the Experts.

Can someone get me started? All I need is a button on a form that will send an e-mail to someone. Since W7 doesn't have an SMTP Service, I'll point it to our Exchange server. I think if I can just get the button to send an e-mail, I can do what I need to do (no, it is NOT spam, it's internal reporting (which Access/Outlook asks (nevermind)).

Thanks VERY much.

Wayne Kessler
WayneKesslerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RDWaibelCommented:
you can use the system.web.mail namespace to do this.

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("luckyperson@online.microsoft.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
smtp.Send(message);
0
WayneKesslerAuthor Commented:
That could very well be what I need, but something is missing.

Remember, I'm so rusty that it's not funny. do i deed do declare or include anything?
0
RDWaibelCommented:
no, this listing SHOULD work as entered  *Smiles
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

WayneKesslerAuthor Commented:
I think the trouble may be that there is no System.Web.Mail Namespace on Windows 7 (64).

Warning      1      Namespace or type specified in the Imports 'System.Web.mail.namespace' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.      C:\Users\WayneK.TECH\documents\visual studio 2010\projects\CommissionMailer\CommissionMailer\Form1.vb      3      9      CommissionMailer
0
RDWaibelCommented:
Quick Q, windows form or web page?
0
WayneKesslerAuthor Commented:
form
0
RDWaibelCommented:
0
WayneKesslerAuthor Commented:
nope. tons of errors.
0
RDWaibelCommented:
hmmmmmmm.
add Imports system.net.mail to the top of your class
Than add this:

    Public Shared Sub SendMail(ByVal strFrom As String, ByVal strTo As String,
        ByVal strSubject As String, ByVal strBody As String)

        'send the email
        Try
            Dim Mailsmtp As New SmtpClient("mail.myserver.com", 25)
            Dim insMail As New MailMessage(strFrom, strTo)
            With insMail
                .Subject = strSubject
                .Body = strBody
            End With
            Mailsmtp.Send(insMail)
        Catch e As Exception
            Console.WriteLine(e.Message)
        End Try

    End Sub
You will need to replace {"mail.myserver.com", 25} with the correct server name and port.
0
WayneKesslerAuthor Commented:
I really appreciate the help here.

No compile errors now, but when I run and click the button, I get:
A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
0
RDWaibelCommented:
what line is erring?
0
WayneKesslerAuthor Commented:
Mailsmtp.Send(insMail)
0
RDWaibelCommented:
ok...  Lets replace the Sub's guts with:

        Try
            Dim Mailsmtp As New SmtpClient("mail.myserver.com", 25)
            Dim insMail As New MailMessage(strFrom, strTo)
            With insMail
                .Subject = strSubject
                .Body = strBody
            End With
            Mailsmtp.Send(insMail)
        Catch smtpEX As SmtpException
            MessageBox.Show(smtpEX.Message)
        Catch e As Exception
            MessageBox.Show(e.Message)
        End Try


and See if we can get more detail about the error.  (I just ran this and got no errors, hmmmmm)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WayneKesslerAuthor Commented:
It worked before trying your last suggestion. I learned a lot! Especially that our Active Directory is not in the best health... (I pulled my PC out of the domain and rejoined it).

Thanks again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.