Rafael
Rafael

Reputation: 802

How to send mail with class (localhost)?

E-mail + Attachment (vCard) send.

I have no Idea what I am doing wrong, searched for similar Questions for 2 days but no question/solution on Stackoverflow or Google fits my description.

Because I've writed my code diffrently

Send Mail + Attachment Class:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Net.Mail;
using System.Net.Configuration;
using Compulutions.Net;
using Compulutions.Web;
using System.IO;
using System.Web.Mail;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.Services.Description;

// System.Web.Mail.SmtpMail.SmtpServer
// using System.Web.Mail.SmtpClient;


namespace vCardGenerator.Website
{
    public class SendvCard
    {
        public void MailvCard(string recipient, string filename)
        {
            Mailer smtp = new Mailer("localhost");

            /* SMTP - port 25 */

            smtp.AddAttachment(filename); //.vcf file Path
            smtp.FromAddress = new MailAddress ("[email protected]");
            smtp.Subject = "vCard";
            smtp.MailBody = "Attachment is a vCard";
            smtp.AddRecipient(recipient);

#if !DEBUG
            try
            {
#endif
                smtp.SendMail();
#if !DEBUG
            }

            catch (Exception ex)
            {
                Response.Write("Exception Occured:   " + ex);
                    //Responds.Write("Sending vCard Failed! Please try again")
            }
#endif


            //  File.Delete(filename);

            //      vCard.vcf Delete after being send
                FileInfo DeleteFileInfo = new FileInfo(filename);

        /*  FileInfo DeleteFileInfo = new FileInfo("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf");
            if (DeleteFileInfo.Exists)
                File.Delete("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf"); */
        }
    }
}

Button Send:

protected void btnSend_Click(object sender, EventArgs e)
{
// Send mail with attachment
using (Attachment data = new Attachment("C:\\local\\vCardGenerator.Website\\" + "FirstName_LastName.vcf", MediaTypeNames.Application.Octet))
{

SendvCard smtp = new SendvCard();
}

lblStatus.Text = "Send to:" + " " + txtMail.Text;

FileInfo DeleteFileInfo = new FileInfo("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf");
if (DeleteFileInfo.Exists)
File.Delete("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" +".vcf");
  }
 }
}

Willing to provide any other/more information if needed.

Trying to get help of the professionals so atleast give me an solution, before burning me.

Sincerely,
Hopeless Creature.

Upvotes: 0

Views: 362

Answers (1)

Darren
Darren

Reputation: 70766

Looks like you have only created an instance of SendvCard and are not invoking the send method in the class (MailvCard).

 SendvCard smtp = new SendvCard();

 smtp.MailvCard("[email protected]", "filename"); // calls the method on the class

Upvotes: 2

Related Questions