4 Replies - 574 Views - Last Post: 11 May 2013 - 04:53 AM Rate Topic: -----

#1 savinayvijay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-May 13

VB.Net Mail Client Help

Posted 10 May 2013 - 09:53 PM

I'm trying to create a simple mail client where user selects a server (currently gmail and hotmail) then fills in the to,subject,body,username and password fields and then click send to send the mail. here's the code

 Imports System.Net.Mail

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ComboBox1.SelectedItem = "Gmail" Then
            Dim mail As New MailMessage
            Dim smtpserver As New SmtpClient("smtp.gmail.com", 587)
            mail.From = New MailAddress(TextBox3.Text)
            mail.To.Add(TextBox1.Text)
            mail.Subject = TextBox2.Text
            mail.Body = RichTextBox1.Text
            smtpserver.UseDefaultCredentials = False
            smtpserver.Credentials = New Net.NetworkCredential(TextBox3.Text, TextBox4.Text)
            smtpserver.Port = 587
            smtpserver.Host = "smtp.gmail.com"
            smtpserver.EnableSsl = True
            smtpserver.Send(mail)
            MsgBox("Sent")
        ElseIf ComboBox1.SelectedItem = "Hotmail" Then
            Dim mail As New MailMessage
            Dim smtpserver As New SmtpClient("smtp.live.com", 587)
            mail.From = New MailAddress(TextBox3.Text)
            mail.To.Add(TextBox1.Text)
            mail.Subject = TextBox2.Text
            mail.Body = RichTextBox1.Text
            smtpserver.UseDefaultCredentials = False
            smtpserver.Credentials = New Net.NetworkCredential(TextBox3.Text, TextBox4.Text)
            smtpserver.Port = 587
            smtpserver.Host = "smtp.live.com"
            smtpserver.EnableSsl = True
            smtpserver.Send(mail)
            MsgBox("Sent")
        End If
    End Sub

End Class 


Gmail seems to work OK but Hotmail doesn't. the weird thing is that I copied the gmail code on hotmail and just changed the server address and port. When I click hotmail and hit send I never get the "Sent" msgbox in the end and neither the mail. I've tried different codes but nothing works even yahoo seems to have the same problem only gmail seems to work. Here, Textbox1 is "To",Textbox2 is "Subject",Textbox3 is "Username",Textbox4 is "Password" and richtextbox1 is "Body".
Please help!!

Is This A Good Question/Topic? 0
  • +

Replies To: VB.Net Mail Client Help

#2 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: VB.Net Mail Client Help

Posted 11 May 2013 - 12:13 AM

Hi,

You could try smtpserver, 25 instead of 587.

Hope it helps,
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3624
  • View blog
  • Posts: 12,541
  • Joined: 12-December 12

Re: VB.Net Mail Client Help

Posted 11 May 2013 - 02:11 AM

There is a slight variation here with EnableSsl = False (and .DeliveryMethod = SmtpDeliveryMethod.Network although this is probably the default). And try port 25.

However, my first priority would be to rename ALL of the controls, then you wouldn't have to say TextBox1 means this, etc.. :dontgetit: :whistling:

This post has been edited by andrewsw: 11 May 2013 - 02:19 AM

Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: VB.Net Mail Client Help

Posted 11 May 2013 - 04:43 AM

I'm pretty sure hotmail and yahoo use port 465 for their SSL smtp

A quick search doesn't seem to agree with me though :D/>

OK, I just tried your code for Hotmail and it does indeed work.

Tests to try. Remark out everything but the hotmail code and try it.

It could be that your combobox selecteditem is not exactly the same as "Hotmail"

Step through the code with the debugger and ensure that it even starts processing the code in that block.

This post has been edited by CharlieMay: 11 May 2013 - 04:55 AM

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3624
  • View blog
  • Posts: 12,541
  • Joined: 12-December 12

Re: VB.Net Mail Client Help

Posted 11 May 2013 - 04:53 AM

I found this quote which seems to clarify:

Quote

Hotmail works on both 25 and 587 with explicit SSL (STARTTLS) and on port 465 with implicit SSL.
Port 587 is currently a default port for MSA without SSL or with explicit SSL.

Personally, I would try the various combinations until it works :)

http://windows.micro...eceive-from-app

This post has been edited by andrewsw: 11 May 2013 - 04:56 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1