Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hellow
i have tryed alot but the following code never sends any Email message to either address,it has no error!,please help
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net.Mime;// for MediaTypeNames

using System.Net;//CredentialCache
using System.Collections;
//http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx
//http://www.codeproject.com/Articles/13236/Sending-complex-emails-in-NET-1-1
namespace Email1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        private void Send_Click(object sender, EventArgs e)
		{   string Myfile = "Abdk.wma";//  <----- window media audio file
            MailAddress from = new MailAddress("ksabtank@hotmail.com", "yahoo");
            MailAddress to = new MailAddress("qazwsxkhalid@yahoo.com", "hotm");
            MailMessage message = new MailMessage(from,to);//, to);
			message.Subject = "Using the new SMTP client.";
			message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
            message.Subject = "Issue Report";
            message.Body = "Submitted By: ";// +txtName.Text + "\n";
            message.Body += "my comment";
            SmtpClient SmtpMail = new SmtpClient();//localhost);//smtp.server.com);//server);
            //SmtpMail.UseDefaultCredentials = true;
            //SmtpMail.Credentials = CredentialCache.DefaultNetworkCredentials;
            //SmtpMail.Credentials = new System.Net.NetworkCredential(str1, str2);//
            //CredentialCache cache = new CredentialCache();

            //SmtpMail.Host = "smtp.gmail.com";
            SmtpMail.Host = "smtp.hotmail.com";
            //SmtpMail.Host = "smtp.yahoo.com";
            SmtpMail.Port = 25;
            SmtpMail.Timeout = 50000;
            SmtpMail.EnableSsl = true;

            Attachment data = new Attachment(Myfile, MediaTypeNames.Application.Octet);//this is the file "Abdk.wma" 
            // Add time stamp information for the file.
            ContentDisposition disposition = data.ContentDisposition;
            disposition.CreationDate = System.IO.File.GetCreationTime(Myfile);
            disposition.ModificationDate = System.IO.File.GetLastWriteTime(Myfile);
            disposition.ReadDate = System.IO.File.GetLastAccessTime(Myfile);
            message.Attachments.Add(data);
        try {
            SmtpMail.Send(message);
		    }  
            catch (Exception ex){
			  Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", 
                    ex.ToString() );			  
                                }
            }
    }
}
Posted
Comments
choudhary.sumit 7-Dec-12 3:21am    
what error u r facing?

1 solution

C#
var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
 
Share this answer
 
Comments
Khalid Sabtan 7-Dec-12 3:39am    
please need your comment On the following

1- smtp.Host = "smtp.hotmail.com";//<-- i hope no error here

2- smtp.Port=587;//<--- what this value could be for hotmail.com

3- smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;//<---i am using a personal computer no network so what this could be?

4- MailAddress from = new MailAddress("ksabtank@hotmail.com", "yahoo");//<-- is this ok

5- MailAddress to = new MailAddress("qazwsxkhalid@yahoo.com", "hotm");//<-- is this ok

6- smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);//<-- fromPassword ,do you mean my password for the sender mail address? ,i mean if i (the sender) want to open my email i do need the password?
[no name] 7-Dec-12 3:45am    
Whats your error???
Khalid Sabtan 7-Dec-12 3:49am    
Whats your error???

i did not tryed your codes yet but i have to to obtain your 6 answers

i am expecting errors
Khalid Sabtan 7-Dec-12 4:09am    
still having 5 errors ,my code becomes

private void Send_Click(object sender, EventArgs e)

{ var smtp = new System.Net.Mail.SmtpClient(); {

string Myfile = "Abdk.wma";// <----- window media audio file

MailAddress from = new MailAddress("ksabtank@hotmail.com", "hot");

MailAddress to = new MailAddress("qazwsxkhalid@yahoo.com", "yahoo");

MailMessage message = new MailMessage(from,to);//, to);

message.Subject = "Using the new SMTP client.";

message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";

message.Subject = "Issue Report";

message.Body = "Submitted By: ";// +txtName.Text + "\n";

message.Body += "my comment"; //***********************

smtp.Host = "smtp.hotmail.com"; smtp.Port = 587; smtp.EnableSsl = true;

smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

smtp.Credentials = new NetworkCredential(from, "qazwsx");

smtp.Timeout = 20000; smtp.Send(from, to, message.Subject, message.Body);
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900