转换vb电子邮件发送代码到c#
本文关键字:代码 vb 电子邮件 转换 | 更新日期: 2023-09-27 18:07:44
目前我使用此代码通过vb应用程序发送电子邮件。我现在不得不使用c#,我想知道是否有类似的东西,我可以在c#中编写,这会做同样的事情?
Set oEmail = CreateObject("CDO.Message")
oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "127.0.0.1"
oEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =25
oEmail.Configuration.Fields.Update
oEmail.From = "test@test.co.uk"
oEmail.To = "test@test.com"
oEmail.Subject = "Subject!!"
oEmail.Textbody = "The body"
oEmail.Send
Set oEmail = nothing
你可以使用SmtpClient类在。net中发送电子邮件:
using (var client = new SmtpClient("127.0.0.1", 25))
using (var message = new MailMessage("from@foo.com", "to@bar.com"))
{
message.Subject = "some subject";
message.Body = "test body";
client.Send(message);
}