开发者

Send email from ASMX web service

开发者 https://www.devze.com 2023-02-15 08:35 出处:网络
Recently somebody answered me on this site, that this method can send email from .net application: public static void SendEmail(bool isHTML, string toEmail, string fromEmail, string subject, string m

Recently somebody answered me on this site, that this method can send email from .net application:

public static void SendEmail(bool isHTML, string toEmail, string fromEmail, string subject, string message)
{
    var sm = new SmtpClient("smtp.mail.ru");
    sm.Credentials = new NetworkCredential开发者_JAVA百科("MyLogin", "MyPass");
    var m = new MailMessage(fromEmail, toEmail) { Subject = subject, Body = message };
    if (isHTML)
    {
        m.IsBodyHtml = true;
    }
    sm.Send(m); // SmtpException
}

It is true. But now I want to use this method from Asp.Net WebService, but I have SmtpException at last string. Why? And do I send email from web service.


So the problem is not with your code, rather the transaction with the SMTP server is failing for some reason. If you have access to the SMTP server, check its logs. Otherwise you might have to use a sniffer like WireShark to figure it out.

To verify this, you can try using a different mail server, assuming you have proper access to that server it should send the mail properly.

0

精彩评论

暂无评论...
验证码 换一张
取 消