Error in Sending Email via a SMTP Client - c#

This may be very trivial for you but i just couldn't figure out why am i getting this error message when i run my code. I looked some of the relative questions on this same website for eg Sending email through Gmail SMTP server with C#
but none of them was helpful. Anyone willing to help please?
using different assemblies are also acceptable. so if anyone got a working solution that would be appreciated.
Error Message = The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
here is my code
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.From = new MailAddress("bob#googlemail.com");
message.To.Add("bob#hotmail.com");
message.Subject = "Hello";
message.Body = "Hello Bob ";
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("MyGoogleMailAccount",
"mygooglemailpassword");
smtpClient.Send(message.From.ToString(), message.To.ToString(),
message.Subject, message.Body);

I don't think there's anything wrong with your code other than the e-mail addresses. I used this code to successfully send an e-mail from gmail to my personal account (ran it in LINQPad, actually). Simply replace the 3 string values with valid values for your accounts and you should be good to go:
MailMessage message = new System.Net.Mail.MailMessage();
string fromEmail = "myaddr#gmail.com";
string fromPW = "mypw";
string toEmail = "recipient#receiver.com";
message.From = new MailAddress(fromEmail);
message.To.Add(toEmail);
message.Subject = "Hello";
message.Body = "Hello Bob ";
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
using(SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587))
{
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromEmail, fromPW);
smtpClient.Send(message.From.ToString(), message.To.ToString(),
message.Subject, message.Body);
}

By this post.
MailMessage mail = new MailMessage("you#yourcompany.com", "user#hotmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);

Related

c# MimeKit mail not sent without error. System.Net.Mail works fine

I made a console application to test MimeKit, it's executed without errors but emails never arrives.
i usae same data with System.Net.Mail and all works fine.
What can be the problem?
MimeKit code:
var email = new MimeMessage();
email.Sender = MailboxAddress.Parse("aa#sbb.com");
email.To.Add(MailboxAddress.Parse("aa.cc#dd.com"));
email.To.Add(MailboxAddress.Parse("bb.dd#dd.com"));
email.Subject = "test";
var builder = new BodyBuilder();
builder.HtmlBody = "corpo";
email.Body = builder.ToMessageBody();
using var smtp = new SmtpClient();
smtp.Connect("smtp.xxx.com", 25, SecureSocketOptions.None);
smtp.Authenticate("ut", "pwd");
smtp.SendAsync(email);
smtp.Disconnect(true);
Console.WriteLine("Email Sent.");
System.mail code:
using (MailMessage mm = new MailMessage())
{
mm.To.Add(new MailAddress("aa.cc#dd.com"));
mm.To.Add(new MailAddress("bb.dd#dd.com"));
mm.From = new MailAddress("aa#sbb.com", "You");
mm.ReplyToList.Add("aa#sbb.com");
mm.Subject = "vecchia mail";
mm.Body = "con system.mail";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.xxx.com";
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential NetworkCred = new NetworkCredential("ut", "pwd");
smtp.Credentials = NetworkCred;
smtp.Port = 25;
Console.WriteLine("Sending Email......");
smtp.Send(mm);
Console.WriteLine("Email Sent.");
}
Thanks to #Klaus Gütter i got the error and then find the solution: a security rule that prevent connection between development machine and mail server, once deployed the application in test environment all works fine.
thanks for suggestions

How to send mail from Smtp client?

I have an console app and I am trying to send mail from it.
My code.
MailMessage message = new MailMessage(MailSender, "ToMe#me.com");
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.";
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
try
{
client.Send(message);
}
catch (Exception ex)
{
string t = ex.Message;
}
Got this from here
I must be missing something since I am getting:
Failure sending mail.
What am I doing wrong here?
EDIT:
inner Exeption.
InnerException = {"The remote name could not be resolved:
'smtp.google.com'"}
You can try to use
smtp.gmail.com
instead of
smtp.google.com
Also try to make sure that you are providing the correct credentials along with the correct port. A server parameter info:
Source
So you can try something like this
MailMessage message = new System.Net.Mail.MailMessage();
string fromEmail = "youremailaddress#xyz.com";
string password = "yourPassword";
string toEmail = "recipientemailaddress#abc.com";
message.From = new MailAddress(fromEmail);
message.To.Add(toEmail);
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.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
using(SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587))
{
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromEmail, password);
smtpClient.Send(message.From.ToString(), message.To.ToString(), message.Subject, message.Body);
}
#Ra3IDeN ...hey brother try this...
SmtpClient smtpClient = new SmtpClient("mail.yourwebsitename.com", 25);
smtpClient.Credentials = new System.Net.NetworkCredential("demo#yourwebsitename.com.com", "yourIdPassword");
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
//code for: From ,CC & To
mail.From = new MailAddress("demo#yourwebsitename.com", "yourwebsite");
mail.To.Add(new MailAddress("demo#yourwebsitename.com"));
mail.CC.Add(new MailAddress("youremailid#gmail.com"));
smtpClient.Send(mail);
If you're trying to send email from a console application (your higher-level problem), I recommend using PostMark. Why:
NuGet - You can get the PostMark NuGet package and send email with a nice API. Convenient and simple.
Not marked as SPAM - You can configure your "server" with verification (including spf and signing). So your email will more likely reach the destination in their inbox rather than their SPAM box.
Free - to a point. I think it's 1000 emails for free then $1 per 1000. So that's pretty good. Compare that to any other vanilla SMTP server for rent. PostMark is cheap
Consistent - From Workstation DEV to server LIVE, the PostMark API is consistently accessible. I cannot stress how good that is. Often a server host will offer SMTP server endpoint but it will only work from inside their network, meaning you have to configure another SMTP server when you're doing DEV work on your workstation (or it simply wont work).
Async Interface - I'm not sure if built-in smtp client in .Net is async...
Tracking - Hey look at that, they have a tracking feature built-in. That's snazzy.
Example code for sending (source):
var message = new PostmarkMessage()
{
To = "recipient#example.com",
From = "sender#example.com",
TrackOpens = true,
Subject = "A complex email",
TextBody = "Plain Text Body",
HtmlBody = "<html><body><img src=\"cid:embed_name.jpg\"/></body></html>",
Tag = "business-message",
Headers = new HeaderCollection{
{"X-CUSTOM-HEADER", "Header content"}
}
};
var imageContent = File.ReadAllBytes("test.jpg");
message.AddAttachment(imageContent, "test.jpg", "image/jpg", "cid:embed_name.jpg");
var client = new PostmarkClient("server token");
var sendResult = await client.SendMessageAsync(message);
MailMessage msg = new MailMessage("YourEmail#gmail.com", "DestinationEmail#something.com");
msg.Subject = message.Subject;
msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString("Message Content here as HTML", null, MediaTypeNames.Text.Html));
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", Convert.ToInt32( 587));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("YourEmail#gmail.com", "YourPassword");
smtpClient.EnableSsl = true;
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (object s,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
};
smtpClient.Credentials = credentials;
smtpClient.Send(msg);

Sending a gmail email

I am trying to send an email through and C# application (Console). Actually I would like it to send an email to any type of email but for the time being if I can get it to send to a gmail account I would be happy enough.
I just want to be able to get this to send to a gmail account for the time being?
Whole Program:
namespace EmailAddress
{
class Program
{
static void Main(string[] args)
{
Program test = new Program();
test.email_send();
}
public void email_send()
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("hg#gmail.com");
mail.To.Add("hg#gmail.com");
mail.Subject = "Test Mail - 1";
mail.Body = "Your attachment is accessible on your computer!";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("g:/example1.txt");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("your mail#gmail.com", "your password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
}
}
New code: Doesn't hang but will not send the message to the inbox
static void Main(string[] args)
{
Program test = new Program();
//test.email_send();
test.CreateTestMessage4();
}
public void email_send()
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("g#gmail.com");
mail.To.Add("g#gmail.com");
mail.Subject = "Test Mail - 1";
mail.Body = "Your attachment is accessible on your computer!";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("g:\\example1.txt");
mail.Attachments.Add(attachment);//list of attachements
smtp.Port = 587;//google standard -- most of the time wouldn't not set
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("*","*");
smtp.Send(mail);
Console.WriteLine("-- Sending Email --");
Console.ReadLine();
}
Can someone try this code and see if it works. For some reason this isn't working so I would like to have someone's fresh perspective of this. I just call this in the main method for an instance of the class.
public void email_send()
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("your email address");
mail.To.Add("your email address");
mail.Subject = "Test Mail - 1";
mail.Body = "Your attachment is accessible on your computer!";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("g:\\example1.txt");
mail.Attachments.Add(attachment);//list of attachements
//smtp.Port = 587;//google standard -- most of the time wouldn't not set
//smtp.EnableSsl = true;
//smtp.UseDefaultCredentials = true;
//smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//smtp.Credentials = new System.Net.NetworkCredential("your address",
"your password");
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("*", "*"); smtp.Send(mail);
Console.WriteLine("-- Sending Email --");
Console.ReadLine();
}
Your code is close:
MailMessage mail = new MailMessage();
using (SmtpClient smtp = new SmtpClient("smtp.gmail.com")) {
mail.From = new MailAddress("haufdoug#gmail.com");
mail.To.Add("haufdoug#gmail.com");
mail.Subject = "Test Mail - 1";
mail.Body = "Your attachment is accessible on your computer!";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("g:\\example1.txt");
mail.Attachments.Add(attachment);
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("your mail#gmail.com", "your password");
smtp.Send(mail);
}
Now, regarding some of your other questions.
Port 587 is used by Google only. Typically the mail server you connect to will tell you what port to use for SMTP mail; Google said there's is 587.
For sending through other servers you typically won't set the port number.
side notes:
SmtpClient implements the IDisposable interface. So it should be wrapped in a using clause to ensure it is properly disposed of when complete. Unless you are using the .SendAsync() method.
I changed the variable name from SmtpServer to smtp for two reasons. First, naming convention. Variables inside a method are recommended to be camel case (forExampleThis). Second, SmtpServer is a misnomer as the object is an SmtpClient. Those are very different things and it's just bad practice to misname things.
Can you try this, it's working for me:
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Port = 587;
SmtpServer.Host = smtp.gmail.com;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.EnableSsl = true;
SmtpServer.Credentials = new System.Net.NetworkCredential("your mail#gmail.com", "your password");

System.Security.Cryptography.CryptographicException: The handle is invalid

I am getting exception while sending mail through C# for
SmtpClient client = new SmtpClient()
as System.Security.Cryptography.CryptographicException: The handle is invalid.
MailMessage mail = new MailMessage(from,to);
mail.To.Add(to);
mail.From = new MailAddress(from, "", System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = fr.message;
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
client.Send(mail);
I am not getting why this happens?
Check your project settings and make sure you have checked NTLM Authentication:

Send email using System.Net.Mail through gmail

I want to send a email through gmail server. I have put the following code but it is getting stuck while sending. Any idea please....
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("apps#xxxx.com");
//create instance of smtpclient
SmtpClient smtp = new SmtpClient();
smtp.Port = 465;
smtp.UseDefaultCredentials = true;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
//recipient address
mail.To.Add(new MailAddress("yyyy#xxxx.com"));
//Formatted mail body
mail.IsBodyHtml = true;
string st = "Test";
mail.Body = st;
smtp.Send(mail);
The xxxx.com is a mail domain in Google apps.
Thanks...
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("apps#xxxx.com");
// The important part -- configuring the SMTP client
SmtpClient smtp = new SmtpClient();
smtp.Port = 587; // [1] You can try with 465 also, I always used 587 and got success
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential(mail.From, "password_here"); // [4] Added this. Note, first parameter is NOT string.
smtp.Host = "smtp.gmail.com";
//recipient address
mail.To.Add(new MailAddress("yyyy#xxxx.com"));
//Formatted mail body
mail.IsBodyHtml = true;
string st = "Test";
mail.Body = st;
smtp.Send(mail);
I tried the above C# code to send mail from Gmail to my Corporate ID. While executing the application the control stopped indefinitely at the statement smtp.Send(mail);
While Googling, I came across a similar code, that worked for me. I am posting that code here.
class GMail
{
public void SendMail()
{
string pGmailEmail = "fromAddress#gmail.com";
string pGmailPassword = "GmailPassword";
string pTo = "ToAddress"; //abc#domain.com
string pSubject = "Test From Gmail";
string pBody = "Body"; //Body
MailFormat pFormat = MailFormat.Text; //Text Message
string pAttachmentPath = string.Empty; //No Attachments
System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpserver",
"smtp.gmail.com");
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpserverport",
"465");
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendusing",
"2");
//sendusing: cdoSendUsingPort, value 2, for sending the message using
//the network.
//smtpauthenticate: Specifies the mechanism used when authenticating
//to an SMTP
//service over the network. Possible values are:
//- cdoAnonymous, value 0. Do not authenticate.
//- cdoBasic, value 1. Use basic clear-text authentication.
//When using this option you have to provide the user name and password
//through the sendusername and sendpassword fields.
//- cdoNTLM, value 2. The current process security context is used to
// authenticate with the service.
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//Use 0 for anonymous
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendusername",
pGmailEmail);
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendpassword",
pGmailPassword);
myMail.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpusessl",
"true");
myMail.From = pGmailEmail;
myMail.To = pTo;
myMail.Subject = pSubject;
myMail.BodyFormat = pFormat;
myMail.Body = pBody;
if (pAttachmentPath.Trim() != "")
{
MailAttachment MyAttachment =
new MailAttachment(pAttachmentPath);
myMail.Attachments.Add(MyAttachment);
myMail.Priority = System.Web.Mail.MailPriority.High;
}
SmtpMail.SmtpServer = "smtp.gmail.com:465";
SmtpMail.Send(myMail);
}
}
Set
smtp.UseDefaultCredentials = false
and use
smtp.Credentials = new NetworkCredential(gMailAccount, password);
This have worked for me:
MailMessage message = new MailMessage("myemail#gmail.com", toemail, subjectEmail, comments);
message.IsBodyHtml = true;
try {
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.Timeout = 2000;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("myemail#gmail.com", "mypassord");
client.Send(message);
message.Dispose();
client.Dispose();
}
catch (Exception ex) {
Debug.WriteLine(ex.Message);
}
BUT (as of the time of this writing - Oct 2017)
You need to ENABLE "Allow less secure apps" inside the option "apps with account access" at the "My account" google security/privacy settings (https://myaccount.google.com)
I realise this is an answer to a very old question, with lots of other good answers. I am posting this code to include some of the useful comments posted by other users such as Using Statements and newer methods where some answers have obsolete methods. This code was tested and working as of 11 July 2018.
If sending via your GMail Account ensure that Allow less secure apps is enabled from your control panel
Class Code C#:
public class Email
{
public void NewHeadlessEmail(string fromEmail, string password, string toAddress, string subject, string body)
{
using (System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage())
{
myMail.From = new MailAddress(fromEmail);
myMail.To.Add(toAddress);
myMail.Subject = subject;
myMail.IsBodyHtml = true;
myMail.Body = body;
using (System.Net.Mail.SmtpClient s = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587))
{
s.DeliveryMethod = SmtpDeliveryMethod.Network;
s.UseDefaultCredentials = false;
s.Credentials = new System.Net.NetworkCredential(myMail.From.ToString(), password);
s.EnableSsl = true;
s.Send(myMail);
}
}
}
}
Class Code VB:
Public Class Email
Sub NewHeadlessEmail(fromEmail As String, password As String, toAddress As String, subject As String, body As String)
Using myMail As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
myMail.From = New MailAddress(fromEmail)
myMail.To.Add(toAddress)
myMail.Subject = subject
myMail.IsBodyHtml = True
myMail.Body = body
Using s As New Net.Mail.SmtpClient("smtp.gmail.com", 587)
s.DeliveryMethod = SmtpDeliveryMethod.Network
s.UseDefaultCredentials = False
s.Credentials = New Net.NetworkCredential(myMail.From.ToString(), password)
s.EnableSsl = True
s.Send(myMail)
End Using
End Using
End Sub
End Class
Usage C#:
{
Email em = new Email();
em.NewHeadlessEmail("myemail#gmail.com", "password", "recipient#email.com", "Subject Text", "Body Text");
}
Usage VB:
Dim em As New Email
em.NewHeadlessEmail("myemail#gmail.com", "password", "recipient#email.com", "Subject Text", "Body Text")
Use Port number 587
With the following code, it will work successfully.
MailMessage mail = new MailMessage();
mail.From = new MailAddress("abc#mydomain.com", "Enquiry");
mail.To.Add("abcdef#yahoo.com");
mail.IsBodyHtml = true;
mail.Subject = "Registration";
mail.Body = "Some Text";
mail.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
//smtp.UseDefaultCredentials = true;
smtp.Credentials = new System.Net.NetworkCredential("xyz#gmail.com", "<my gmail pwd>");
smtp.EnableSsl = true;
//smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);
But, there is a problem with using gmail. The email will be sent successfully, but the recipient inbox will have the gmail address in the 'from address' instead of the 'from address' mentioned in the code.
To solve this, please follow the steps mentioned at the following link.
http://karmic-development.blogspot.in/2013/10/send-email-from-aspnet-using-gmail-as.html
before following all the above steps, you need to authenticate your gmail account to allow access to your application and also the devices. Please check all the steps for account authentication at the following link:
http://karmic-development.blogspot.in/2013/11/allow-account-access-while-sending.html
ActiveUp.Net.Mail.SmtpMessage smtpmsg = new ActiveUp.Net.Mail.SmtpMessage();
smtpmsg.From.Email = "abcd#test.com";
smtpmsg.To.Add(To);
smtpmsg.Bcc.Add("vijay#indiagreat.com");
smtpmsg.Subject = Subject;
smtpmsg.BodyText.Text = Body;
smtpmsg.Send("mail.test.com", "abcd#sss.com", "user#1234", ActiveUp.Net.Mail.SaslMechanism.Login);
simple code works
MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(address, password);
smtp.Send(mail);

Categories

Resources