问题描述
我使用outloook 2003和Visual Studio 2008。我想开发将发送电子邮件给任何域的应用程序。但是,当我尝试发送电子邮件到Gmail我的code失败,Hotmail服务等,实际上所有的信息都存储在 C:\的Inetpub \ mailroot \队列
目录。请帮我,我怎么发送邮件到gmail,hotmail的的A / C。
在此先感谢
code是
System.Net.Mail.MailMessage消息=新System.Net.Mail.MailMessage();
message.To.Add([email protected]);
message.To.Add([email protected]);
message.Subject =这是邮件样本;
message.From =新System.Net.Mail.MailAddress([email protected]);
message.Body =这是邮件正文;
System.Net.Mail.SmtpClient SSS =新System.Net.Mail.SmtpClient(HO-KKJ-MAIL.in.niit.com);
sss.UseDefaultCredentials = FALSE;
sss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
sss.Credentials =新System.Net.NetworkCredential(Sumit.Dhingrar,密码,域);
这是在 C#发送电子邮件与
的Gmail
一个很好的样本
从string = [email protected]; //用自己的正确的Gmail地址来替换这
字符串= [email protected] //使用的电子邮件地址,你要发送的邮件的人替换该
System.Net.Mail.MailMessage邮件=新System.Net.Mail.MailMessage();
mail.To.Add(到);
mail.From =新MailAddress(从一鬼情未了,System.Text.Encoding.UTF8);
mail.Subject =这是一个测试邮件;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body =这是电子邮件正文文本;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = TRUE;
mail.Priority = MailPriority.High;
SmtpClient客户端=新SmtpClient();
//添加Creddentials-使用自己的电子邮件ID和密码
client.Credentials =新System.Net.NetworkCredential(从密码);
client.Port = 587; // Gmail的作品在此端口上
client.Host =smtp.gmail.com;
client.EnableSsl = TRUE; // Gmail的工作在服务器抵押层
尝试
{
client.Send(邮件);
}
赶上(例外前)
{
异常EX2 =前;
字符串的errorMessage =的String.Empty;
而(EX2!= NULL)
{
的errorMessage + = ex2.ToString();
EX2 = ex2.InnerException;
}
HttpContext.Current.Response.Write(的errorMessage);
} //结束试
您确定
message.From =新System.Net.Mail.MailAddress([email protected]);
是正确的?请问这种方法有一个重载这样吗?
I am using outloook 2003 and visual studio 2008. i want to develop an application that will send the email to any domain. but my code fails when i'm trying to send email to gmail, hotmail etc. actually all the messages is stored in C:\Inetpub\mailroot\Queue
directory. Please help me how i send the email to gmail, hotmail a/c.
Thanks in Advance
Code is
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("[email protected]");
message.To.Add("[email protected]");
message.Subject = "This is sample mail";
message.From = new System.Net.Mail.MailAddress("[email protected]");
message.Body = "this is the message body";
System.Net.Mail.SmtpClient sss = new System.Net.Mail.SmtpClient("HO-KKJ-MAIL.in.niit.com");
sss.UseDefaultCredentials = false;
sss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
sss.Credentials = new System.Net.NetworkCredential("Sumit.Dhingrar", "password","domain");
This is a good sample for Sending E-Mail with Gmail
in C#
string from = [email protected]; //Replace this with your own correct Gmail Address
string to = [email protected] //Replace this with the Email Address to whom you want to send the mail
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "One Ghost" , System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail" ;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true ;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(from, "Password");
client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
HttpContext.Current.Response.Write(errorMessage );
} // end try
Are you sure
message.From = new System.Net.Mail.MailAddress("[email protected]");
is right? Does this method have an overload like this?
这篇关于如何发送电子邮件,在C#中使用SMTPclient到Gmail吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!