Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 6-Dec-12 21:17pm
Comments
choudhary.sumit at 7-Dec-12 3:21am
   
what error u r facing?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
  Permalink  
Comments
Khalid Sabtan at 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?
Krunal Rohit at 7-Dec-12 3:45am
   
Whats your error???
Khalid Sabtan at 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 at 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)

  Print Answers RSS
0 OriginalGriff 324
1 Maciej Los 239
2 Sergey Alexandrovich Kryukov 182
3 CPallini 120
4 Richard MacCutchan 120
0 OriginalGriff 5,474
1 Sergey Alexandrovich Kryukov 4,713
2 Peter Leow 2,944
3 DamithSL 2,465
4 Maciej Los 2,434


Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid