在System.Net.Mail中发送电子邮件 [英] Sending email in System.Net.Mail

查看:73
本文介绍了在System.Net.Mail中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我的服务器管理员告诉我,将发送电子邮件的身份验证方法设置为true.
你能告诉我该怎么办?电子邮件的身份验证方法是什么?

这是我的代码和用于发送电子邮件的web.config:

Hi every one.
My server administrator told me that set true your authenticatio method for sending email.
can u tell me what can i do? and what is Authentication method for Email ?

Here is my code and my web.config for sending emails :

<system.net>
    <mailSettings>
        <smtp from="info@amicoyasnapars.com">

            <network host="mail.amicoyasnapars.com" port="25" userName="info@amicoyasnapars.com" password="mypassword" defaultCredentials="false"/>
        </smtp>
    </mailSettings>
</system.net>




发送后的C#代码:




C# Code Behind for sending :

public bool SendContact(string FullName, string UserEmail, string Comment, int Lang, string Phone)
{
    try
    {
        CTable = CompClass.Get_2142Items(Lang);

        SmtpClient smtp = new SmtpClient();
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();

        //From Customer To Us!
        message.To.Add("info@amicoyasnapars.com");
        //message.From = MailFAddress;
        message.Subject = "New Contact From Site";
        message.IsBodyHtml = true;

        //888888888888888888888888888888888888888888888888888888
        message.Body = "<font face='Tahoma' size='2'><strong>نام کامل : </strong></font>" + FullName + "<br>";
        message.Body += "<font face='Tahoma' size='2'><strong>ایمیل : </strong></font>" + UserEmail + "<br>";
        message.Body += "<font face='Tahoma' size='2'><strong>تلفن : </strong></font>" + Phone + "<br>";
        message.Body += "<font face='Tahoma' size='2'><strong>پیام : </strong></font>" + Comment + "<br>";
        //888888888888888888888888888888888888888888888888888888

        message.BodyEncoding = System.Text.Encoding.UTF8;
        smtp.Send(message);
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }
}



谢谢大家.



Thank u all.

推荐答案

这里有完整的通用电子邮件发送例程:
There is a complete Generic routine for Email sending here: Sending an Email in C# with or without attachments: generic routine.[^]


这篇关于在System.Net.Mail中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆