将vb电子邮件发送代码转换为c# [英] convert vb email send code to c#
本文介绍了将vb电子邮件发送代码转换为c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前,我使用此代码通过vb应用程序发送电子邮件。我现在不得不使用c#,我想知道是否可以在c#中写类似的东西来做同样的事情?
currently i use this code to send an email through vb applications. I am now having to use c# and i was wondering if there was something similar i could write in c# which would do the same?
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中发送电子邮件:
You could use the SmtpClient class to send email in .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);
}
这篇关于将vb电子邮件发送代码转换为c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文