电子邮件邮件设施 [英] email mail facilities
问题描述
亲爱的朋友,
我想使用电子邮件功能.
您能告诉我如何编写代码吗?
如何使用SMTP和其他服务?
直到现在我都没用过.
请帮助我.
我还想按照时间设置为自动生成的邮件编写代码.
Dear friends,
I would like to use email facilities.
Can you tell me how to how to write code for that?
How to use SMTP and other service?
I have never use till now.
Please help me.
I would also like to write code for auto generated mail as per time set.
推荐答案
尝试 ^ ].
sendEmail(测试主题","me@mail.com","to@mail.com",电子邮件正文",",",空);
公共静态布尔sendEmail(字符串strSubject,字符串strFrom,字符串strTo,字符串strBody,字符串strCc,字符串strBcc,字符串displayName)
{
System.Net.Mail.SmtpClient Mail =新的System.Net.Mail.SmtpClient();
Mail.Host = clsCommon.value("SMTPServer").ToString();
字符串username = null;
字符串密码= null;
Mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
username ="MailUserName";
密码="MailPassword";
System.Net.NetworkCredential basicAuthenticationInfo =新的System.Net.NetworkCredential(用户名,密码);
Mail.UseDefaultCredentials = false;
Mail.Credentials = basicAuthenticationInfo;
System.Net.Mail.MailMessage myMail =新的System.Net.Mail.MailMessage();
myMail.Subject = strSubject;
myMail.From =新的System.Net.Mail.MailAddress(strFrom,displayName);
myMail.To.Add(新System.Net.Mail.MailAddress(strTo));
如果(!string.IsNullOrEmpty(strCc))
{
myMail.CC.Add(新System.Net.Mail.MailAddress(strCc));
}
如果(!string.IsNullOrEmpty(strBcc))
{
myMail.Bcc.Add(新System.Net.Mail.MailAddress(strBcc));
}
myMail.IsBodyHtml = true;
myMail.Body = strBody;
试试
{
Mail.Send(myMail);
返回true;
}
catch(ex ex例外)
{
ex.Message.ToString();
返回false;
}
}
sendEmail("Test Subject", "me@mail.com", "to@mail.com", "Body of email", "", "",null);
public static bool sendEmail(string strSubject, string strFrom, string strTo, string strBody, string strCc, string strBcc,string displayName)
{
System.Net.Mail.SmtpClient Mail = new System.Net.Mail.SmtpClient();
Mail.Host = clsCommon.value("SMTPServer").ToString();
string username = null;
string Password = null;
Mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
username = "MailUserName";
Password = "MailPassword";
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(username, Password);
Mail.UseDefaultCredentials = false;
Mail.Credentials = basicAuthenticationInfo;
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
myMail.Subject = strSubject;
myMail.From = new System.Net.Mail.MailAddress(strFrom,displayName);
myMail.To.Add(new System.Net.Mail.MailAddress(strTo));
if (!string.IsNullOrEmpty(strCc))
{
myMail.CC.Add(new System.Net.Mail.MailAddress(strCc));
}
if (!string.IsNullOrEmpty(strBcc))
{
myMail.Bcc.Add(new System.Net.Mail.MailAddress(strBcc));
}
myMail.IsBodyHtml = true;
myMail.Body = strBody;
try
{
Mail.Send(myMail);
return true;
}
catch (Exception ex)
{
ex.Message.ToString();
return false;
}
}
namespace System.net.mail;
您必须在单击要发送按钮单击事件的邮件的按钮时编写此代码.
字符串s1 ="m.kalaingar@gmail.com";
字符串s2 = TextBox1.Text;
字符串s3 = TextBox2.Text;
字符串正文="dfhfhkjsdhgfjksdfhkjsfgjksfjksdhfsdfaskjfsdjkfh";
MailMessage邮件=新的MailMessage();
mail.From =新的MailAddress(s1);
mail.To.Add(s2);
mail.Subject = s3;
mail.Body = body;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal;
SmtpClient smtp =新的SmtpClient();
smtp.Send(mail);
Response.Write(您的消息发送成功");
您必须将此代码添加到您的webconfig
you have to write this code when you click the button you want to send mail that button click event.
string s1="m.kalaingar@gmail.com";
string s2 = TextBox1.Text;
string s3 = TextBox2.Text;
string body = "dfhfhkjsdhgfjksdfhkjsfgjksfjksdhfsdfaskjfsdjkfh";
MailMessage mail = new MailMessage();
mail.From = new MailAddress(s1);
mail.To.Add(s2);
mail.Subject = s3;
mail.Body = body;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal;
SmtpClient smtp = new SmtpClient();
smtp.Send(mail);
Response.Write("your message send successfully");
you have to add this code to your webconfig
<system.net>
<mailSettings>
< smtp from ="m.kalaingar@gmail.com">
< network host ="smtp.gmail.com" port ="465" username ="yourgmailid" password ="yourpassword">
<smtp from="m.kalaingar@gmail.com">
<network host="smtp.gmail.com" port="465" username="yourgmailid" password="yourpassword">
这篇关于电子邮件邮件设施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!