我很感激这个问题的帮助,这个问题耗费了很多时间。 我有这段代码:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Label1.Text = "924 695 302"
Label2.Text = "690 142 449"
Dim ipvisitante = Request.ServerVariables("remote_addr")
Dim hoje = DateTime.Now
Dim informacao = ipvisitante & " --- " & hoje
'Send e-mail
Dim strFrom = "fernandopessoa@fpessoa.net" ''IMPORTANT: This must be same as your smtp authentication address.
Dim strTo = "francopessoa.espana@hotmail.com"
Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo))
MailMsg.BodyEncoding = Encoding.Default
MailMsg.Subject = "This is a test"
MailMsg.Body = "This is a sample message using SMTP authentication"
MailMsg.Priority = MailPriority.High
MailMsg.IsBodyHtml = True
'Smtpclient to send the mail message
Dim SmtpMail As New SmtpClient
Dim basicAuthenticationInfo As New Net.NetworkCredential("fernandopessoa@fpessoa.net", "---------")
''IMPORANT: Your smtp login email MUST be same as your FROM address.
SmtpMail.Host = "mail.fpessoa.net"
SmtpMail.UseDefaultCredentials = False
SmtpMail.Credentials = basicAuthenticationInfo
MsgBox("O ficheiro existe", MsgBoxStyle.Information, "SIM")
'Write to txt File
FileOpen(1, "visitas.txt", OpenMode.Append)
WriteLine(1, informacao)
FileClose()
End Sub
现在,当页面加载时,文本会在标签中出现。 令人惊讶的是,它不会执行其余代码,显示Msgbox,写入.txt文件并发送电子邮件。
有人能给我一些关于我的代码出错的线索吗?
提前致谢。
答案 0 :(得分:0)
代码执行...它在 Web服务器上运行。它在客户端的Web浏览器中运行不,永远不会。
这解释了MsBox()和文件,虽然Web服务器也可能挂起等待有人在MsgBox上单击“Okay”,没有人会看到。对于电子邮件,您永远不会致电SmtpMail.Send(MailMsg)
当我在这里时,该文件代码使用的是古董api。
听起来你需要快速了解这一切是如何运作的,所以这是一步一步发生的事情: