Visual Basic中的电子邮件按钮编码问题。 [英] E-mail button coding problem in Visual Basic.
问题描述
有谁知道有任何第三方免费软件可以取代EASendMailObj.Mail吗?或者使用EASendMailObjLib.Mail的任何方法都成为免费软件?因为现在..我用它来发送电子邮件,系统说Smtp.LicenseCode =TryIt已经过期。以下是我的代码:
Does anyone know have any third party freeware can replace EASendMailObj.Mail? Or any method to use the EASendMailObjLib.Mail become freeware? Because now..I use this to send email,the system say Smtp.LicenseCode = "TryIt" has expired already.The following is my code:
Dim Smtp As New EASendMailObjLib.Mail
Smtp.LicenseCode = "TryIt"
Smtp.FromAddr = eid '"ab@mail.com"
Smtp.AddRecipientEx(email, 0)
Smtp.Subject = "abcde"
Smtp.BodyText = "abcde"
'' Add attachment from local disk
If Smtp.AddAttachment(pdfFile) <> 0 Then
MsgBox("Failed to add attachment with error:" & Smtp.GetLastErrDescription())
End If
Smtp.ServerAddr = server '"smtp.gmail.com"
Smtp.ServerPort = port ' 465
'' detect SSL/TLS automatically
Smtp.SSL_init()
Smtp.UserName = eid '"ab@mail.com"
Smtp.Password = pass '"123"
If Smtp.SendMail() = 0 Then
'' MsgBox("email was sent successfully!")
Label1.Text = "1"
Else
MsgBox("failed to send email with the following error:" & Smtp.GetLastErrDescription())
End If
Else
End If
Next
If Label1.Text = "1" Then
MsgBox("email was sent successfully!")
End If
Label1.Text = ""
End If
我解决了这个问题1一周已经,但也不能解决它。希望你们能帮助我,真的让这个部分头疼。
提前谢谢你。
代码块添加格式[/ Edit]
I solve this problem about 1 week already,but also cannot solve it.Hope u guys can help me,really headache for this part.
Thanks you in advance.
Code block formatting added[/Edit]
推荐答案
你真的不需要使用第三方库发送电子邮件。只需使用System.Net.Mail.SmtpClient
:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx [ ^ ]
使用或不使用附件在C#中发送电子邮件:generic例程。 [ ^ ](C#)
使用或不使用附件在C#中发送电子邮件:通用例程。 [ ^ ](V B.NET)
示例:
Hi,
You really don't need to use a third-party library to send an email. Just use aSystem.Net.Mail.SmtpClient
:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx[^]
Sending an Email in C# with or without attachments: generic routine.[^] (C#)
Sending an Email in C# with or without attachments: generic routine.[^] (VB.NET)
Example:
Imports System.Net
Imports System.Net.Mail ' add these lines at the top of your file
Dim Smtp As New SmtpClient(server, port)
Dim msg As New MailMessage()
msg.From = New MailAddress(eid)
msg.[To].Add(email)
msg.Subject = "abcde"
msg.Body = "abcde"
msg.IsBodyHtml = True
' if your email body is not HTML, change this into false or remove this line
msg.Attachments.Add(New Attachment(pdfFile))
Smtp.EnableSsl = True
Smtp.Credentials = New NetworkCredential(eid, pass)
Try
Smtp.Send(msg)
Label1.Text = "1"
Catch e As Exception
MsgBox("failed to send email with the following error:" + e.Message)
End Try
' now, add other code if you want
希望这有帮助。
Hope this helps.
这篇关于Visual Basic中的电子邮件按钮编码问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!