convert vb email send code to c# [closed]

南楼画角 提交于 2019-12-13 09:54:53

问题


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

回答1:


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);
}


来源:https://stackoverflow.com/questions/7331372/convert-vb-email-send-code-to-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!