1

I'm adding an email sender in my app, so i used this:

Try
    Dim oMail As New SmtpMail("TryIt")
    Dim oSmtp As New SmtpClient()
    oMail.From = "app-NHK@hotmail.com" ' From
    oMail.To = "NHKomaiha@hotmail.com" ' To
    oMail.Subject = Title.Text 'Title
    oMail.TextBody = MsgTxt.Text 'Body
    Dim oServer As New SmtpServer("smtp.live.com") ' SMTP server address
    oServer.User = "app-NHK@hotmail.com" 'here i have written my app's email address made for sending the email from this form
    oServer.Password = "thepassword" 'here i have put my app email password
    oServer.ConnectType = SmtpConnectType.ConnectSSLAuto ' if SSL connection required
    UseWaitCursor = True

Here done setting the main needed info

    oSmtp.SendMail(oServer, oMail)

Sending...

    UseWaitCursor = False
    MessageBox.Show("E-Mail Sent Successfully", "Contact by E-Mail", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Main.BringToFront()
    Main.Enabled = True
    Close()

Error catching...

Catch ep As Exception
    UseWaitCursor = False
    MessageBox.Show("Error while sending E-Mail." & vbCrLf & vbCrLf & ep.Message, "Contact by E-Mail", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Dim closeerror = MessageBox.Show("Do you want to close?", "Contact by E-Mail", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If closeerror = DialogResult.Yes Then
        Main.BringToFront()
        Main.Enabled = True
        Close()
    End If
End Try

Is this code wrong? i used a lot of ways to send email but none worked

This time i got error: 550 5.3.4 Requested action not taken; To continue sending messages, please sign in to your account.

Galacticai
  • 87
  • 1
  • 13

2 Answers2

2

Modify and try this working example:

Imports System.Net.Mail
...
Try
    Dim Email As New MailMessage()
    Email.From = New MailAddress("abcdef@gmail.com")
    Email.To.Add("other@provider.com")
    Email.Subject = "Subject"
    Email.IsBodyHtml = False        'or true if you want html
    Email.Body = TextBox1.Text

    Dim EmailClient As New SmtpClient("smtp.gmail.com", 587)
    EmailClient.EnableSsl = True
    EmailClient.Credentials = New Net.NetworkCredential("abcdef@gmail.com", "password")
    EmailClient.Timeout = 7000
    EmailClient.Send(Email)

Catch ex As SmtpException
    MsgBox(ex.StatusCode & vbCrLf & ex.Message, vbCritical, "SMTP Error!")
End Try
c4pricorn
  • 3,471
  • 1
  • 11
  • 12
  • code is right but error: 550 mailbox is unabvailable – Galacticai Nov 12 '15 at 19:40
  • And got the same text of the above `ex.Message` (`5.3.4 requested action...etc..`) – Galacticai Nov 12 '15 at 19:47
  • 1
    Code was tested with many servers and works properly. I think that problem is with configuraton. See: https://together.jolla.com/question/59505/solvedhow-to-setup-outgoing-smtp-server-for-hotmail-on-jolla/ – c4pricorn Nov 12 '15 at 19:54
  • I've not got a solution from this link, I'm not finding any wrong thing in my configuration i tried changing to `smtp-mail.outlook.com` and changing port, but now the error is `timed out` – Galacticai Nov 12 '15 at 22:36
0

Usually you need to specify port and authentication type in order to connect to an smtp server. It seems that smtp.live.com use SSL and port 465 (please verify this data).

So you can use SmtpClient.Port property to sets the port used for SMTP transactions and SmtpClient.EnableSSL to specify that SmtpClient uses Secure Sockets Layer (SSL) to encrypt the connection.

tezzo
  • 10,858
  • 1
  • 25
  • 48