الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكله عند ارسال (او محاولة ارسال) ايميل

مغلق
بدأه زائرة عربية في 10 نوفمبر 2006 · 2 رد · 986 مشاهدة · في برمجة الشبكات والتطبيقات الموزعة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

السلام عليكم ورحمة الله وبركاته،

انا اشتغل على windows xp home edition و visual studio 2003 .net

عندي برنامج بسيط يحاول ارسال ايميل

انشأت ايميل جديد مع google لاستخدام الـsmtp

وعندي هذا الكود:

void sendEmail()
{
	try
	{
		try
		{
			MailMessage message = new MailMessage();
				//Because using google server, requires SSL
			message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
			message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1 );
			message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername","SmtpHostUserName" );
			message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","SmtpHostPassword" );

			message.From = "mygmail@gmail.com";
			message.To = "myyahoo@yahoo.com";
			message.Subject = "Test Subject";
			message.Body = "Test Body";

			try
			{		
				SmtpMail.SmtpServer = "smtp.google.com";
				SmtpMail.Send(message);
			}
			catch(System.Web.HttpException ehttp)
			{
				MessageBox.Show("Catch1");
				MessageBox.Show(ehttp.ToString());
			}
		}
		catch(IndexOutOfRangeException)
		{
			MessageBox.Show("IndexOutOfRangeException");
		}
	}
	catch(System.Exception e)
	{
		MessageBox.Show("Catch2");
		MessageBox.Show(e.ToString());
	}
}//end sendEmail function

عند التنفيذ، يطلع لي هذه الـexception عند الـcatch الاول

System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->System.Runtime.InteropServices.COMException(0x80040213):The transport failed to connect to the server.

ارجوا المساعده لحل هذه المشكله

شكرا و -waf

#2

الكود من النظرة الأولى يبدوا صحيحا ولكن هل Google تسمح بإستخدام smtp من جهه خارجية

بعض المزودات لا تسمح ربما هذا السبب

اطيب تحيه لك

#3

بسم الله الرحمن الرحيم

شكرا لك حمد

الحمدلله، اضفت بعض الكود :

message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");

وغيرت الـsmtpserver الى:

SmtpMail.SmtpServer = "smtp.gmail.com";

والحمدلله مشي معاي الكود :D

هذا الموضوع مغلق.

مواضيع مشابهة