Email App

acd17

Member
Joined
Apr 16, 2009
Messages
6
Programming Experience
Beginner
I have been trying to make my own app for sending emails. But I have been trying to make it where I don't have to sign into my hotmail account, it just does it automatically. Then all I need to do is fill out the recipients, subject, and body for the message and hit send but I am having issues. I can't for the life of me get it to work. After a week of messing around with it and scouring the internet for help, I have gotten to where the only error I get is, failure to send message.

VB.NET:
Imports System.Net.Mail

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Message As MailMessage = New MailMessage()
        Dim Smtp As New SmtpClient()
        Dim SmtpUser As New System.Net.NetworkCredential()
        '-- Build Message
        Message.From = New MailAddress("myemail@hotmail.com", "SMTP.live.com")
        Message.To.Add(New MailAddress("recipientsemails@_____.com"))
        Message.IsBodyHtml = False
        Message.Subject = "textbox1.text"
        Message.Body = "textbox2.text"
        '-- Define Authenticated User
        SmtpUser.UserName = "myusername"
        SmtpUser.Password = "mypassword"
        SmtpUser.Domain = "@hotmail.com"
        '-- Send Message
        Smtp.UseDefaultCredentials = False
        Smtp.Credentials = SmtpUser
        Smtp.Host = "SMTP.live.com"
        Smtp.DeliveryMethod = SmtpDeliveryMethod.Network
        Smtp.Send(Message)
        MessageBox.Show("Message Sent.", "Congratulations", _
        MessageBoxButtons.OK, MessageBoxIcon.Information)
        Me.Close()
    End Sub
End Class


Please, I need some help and am getting frustrated with this.
I have been working on this because I can't use Outlook with hotmail and I figured it would be interesting to try, but it turns out to be a lot harder than I expected. Any help would be appreciated, but all I have been getting on other forums is just links to other topics and they are all different so that have just confused me more. If someone could look at my code and just point me in the right direction, I would love it.

Thanks for any help I receive.
 
At the very least put your code into a Try block so you can catch a error coming down:

Try
(Your Code)
Catch Ex as Exception
MsgBox("The error was: " & Ex.Message)
End Try

Then from the error (if it's generating one) you can give yourself a idea on whats going on.
 
I actually do have it in one, I just copied this code from a post in another forum that I made. But I don't under stand what is wrong. Everything looks right and all it tell me is Failure to send email. (not the message I made, but a visualStudio error). Thats all the info. it gives me and I am clueless with this email thing in VB. Its all new to me.

VB.NET:
        Try
            Smtp.Send(Message)
            MessageBox.Show("Email Sent!", "Success", _
        MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Close()
        Catch
            MessageBox.Show("Failure to send email.", "Failed", _
       MessageBoxButtons.OK, MessageBoxIcon.Error
)
 
Yeah, all your getting is your message box. Catch the actual exception like I listed in my code and see what the error message is.
 
ok. I did what you said and got this error message. I had it one other time and couldn't find a way to fix it. I have done a lot of research and still cant grasp how to make an app that can send emails.
 

Attachments

  • error.jpg
    error.jpg
    17.7 KB · Views: 41
Smtp.Port=25 'Thats for hotmail/live / I think gmail is 587

Take a look at this piece of code, i used it and it worked.

VB.NET:
          Dim mailman As New System.Net.Mail.SmtpClient
            Dim email As New Net.Mail.MailMessage("me@me.com","to@to.com")

            email.Subject = "Subject"
            email.IsBodyHtml = True
            email.Body = "Body"

            mailman.Host = "smtp.live.com"
            mailman.Port = 25
            Dim auth As New System.Net.NetworkCredential
            auth.UserName = "myaccount@live.com"
            auth.Password = "mypassword"
            mailman.UseDefaultCredentials = False
            mailman.Credentials = auth
            mailman.EnableSsl = True

mailman.send(email)
 
It feels like im getting there but i got the same error again. do I have to do something with Starttls or something like that.
 
hey, I didnt see the code you posted before I did, and I tried it out and it worked. I owe you one man. Its so simple but yet I had so much trouble with it. now its starting to make a bit more sense to me.

THANK YOU!
 
Back
Top