我在我的应用中添加了电子邮件发件人,所以我使用了这个:
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
这里设置了主要所需信息
oSmtp.SendMail(oServer, oMail)
发送...
UseWaitCursor = False
MessageBox.Show("E-Mail Sent Successfully", "Contact by E-Mail", MessageBoxButtons.OK, MessageBoxIcon.Information)
Main.BringToFront()
Main.Enabled = True
Close()
错误捕捉......
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
这段代码错了吗?我使用了很多方法来发送电子邮件但没有工作
这次我收到错误:550 5.3.4 Requested action not taken; To continue sending messages, please sign in to your account.
答案 0 :(得分:2)
修改并尝试这个工作示例:
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
答案 1 :(得分:0)
通常,您需要指定端口和身份验证类型才能连接到smtp服务器。似乎smtp.live.com
使用SSL
和端口465
(请验证此数据)。
因此,您可以使用SmtpClient.Port属性设置用于SMTP事务的端口,并SmtpClient.EnableSSL指定SmtpClient
使用安全套接字层(SSL)加密连接。