Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Montei um formulário com os campos Nome, Email, Assunto, Corpo do Texto. E no botão enviar coloquei o seguinte evento:
Private Sub EnviarEmail()
If txt_Nome.Text <> "" And txt_Email.Text <> "" And txt_Assunto.Text <> "" And txt_Corpo.Text <> "" Then
Try
Dim objMail As New MailMessage
objMail.From = txt_Email.Text
objMail.To = "email@live.com" <!-- Removi meu e-mail pois ninguém precisa saber meu email ;D -->
objMail.Subject = txt_Assunto.Text
objMail.Body = txt_Corpo.Text
objMail.BodyFormat = MailFormat.Text
SmtpMail.SmtpServer = "mail.live.com"
SmtpMail.Send(objMail)
Label4.Text = "Email enviado com sucesso!"
Catch ex As Exception
Label4.Text = ex.ToString <!-- Deixei esse campo apenas para visualizar os erros. Quando rodar beleza, vou pensar em outra forma de visualizar o erro -->
End Try
Else
MsgBox("Todos os campos são obrigatórios!!!")
End If
LimparCampos
End Sub
O erro está sendo com o servidor smtp do hotmail. Alguém sabe como consertar isso?
System.Web.HttpException (0x80004005): Falha na conexão do transporte com o servidor. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Falha na conexão do transporte com o servidor. --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at ASP.index_temp_aspx.EnviarEmail() in E:\Trabalho\Projetos\MeuSite\MeuSite\index_temp.aspx:line 17
Alguma dica de como fazer o smtp funcionar?
Obrigado!
Obs.: A linha 17 é essa:
SmtpMail.Send(objMail)
Carregando comentários...