Sending Mail Failure: SMTP Exception
I'm writing in the hope that you will help me. Today I'm going to develop a mail application using vb.net, for this I wrote the code given below.
This code throws the exception ("SMTP Exception")
Public Function SendAnEmail(ByVal MsgBody As String)
Try
Dim MsgFrom As String = "amolkadam.a@gmail.com"
Dim MsgTo As String = "amolkadam.a@gmail.com"
Dim MsgSubject As String = "claim Report"
' Pass in the message information to a new MailMessage
Dim msg As New Net.Mail.MailMessage(MsgFrom, MsgTo, MsgSubject, MsgBody)
' Create an SmtpClient to send the e-mail
Dim mailClient As New SmtpClient("219.64.91.90") ' = local machine IP Address
' Use the Windows credentials of the current User
mailClient.UseDefaultCredentials = True
' Pass the message to the mail server
mailClient.Send(msg)
开发者_运维问答 ' Optional user reassurance:
MessageBox.Show(String.Format("Message Subject ' {0} ' successfully sent From {1} To {2}", MsgSubject, MsgFrom, MsgTo), "EMail", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
' Housekeeping
msg.Dispose()
Catch ex As FormatException
MessageBox.Show(ex.Message & " :Format Exception")
Catch ex As SmtpException
MessageBox.Show(ex.Message & " :SMTP Exception")
End Try
End Function
You've written the code to use your own PC as the mail server, is that correct? Just so you haven't misunderstood that the IP sent in to SmtpClient
should be the IP of the server.
If you do have an SMTP server running on your local PC, have you tried that you can send emails from that server via some other client? And that the server will accept emails with a from
containing a gmail.com address (some servers won't).
You can try this using any telnet client by following the instructions here, just exchanging the addresses as needed.
精彩评论