I am currently sending mails from my code using smtp, but seems like we will have to migrate to exchange server, is there a difference between the two?
What changes I need to do in my code?
MailMessage loginInfo = new MailMessage();
loginInfo.To.Add("estinationaddress.#ca");
loginInfo.From = new MailAddress("abc#sde.ca");
loginInfo.Subject = "ABC";
loginInfo.Body = "Your username is: " +"abc";
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "www.smtphost.com";
smtp.Port = 25;
smtp.EnableSsl = false;
smtp.Credentials = new System.Net.NetworkCredential("abc#sde.ca","abc");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(loginInfo);
What changes I will be needing in my code?
Related
I want to send email to two users when the count is not zero. When I am making
$semail = $row_seller['seller_email']; its working but when I make it
$semail = $row_seller['seller_email'].",example#gmail.com"; its not, I want to send it to both. How can i do it.
<?php
$query1 = "select * from `seller` where seller_pincode = $pincode";
$run_query1 = mysqli_query($con, $query1);
$count_seller = mysqli_num_rows($run_query1);
if ($count_seller == 0)
{
$semail = "example#gmail.com";
$sname = $saddress = $spincode = $scity = $sstate = $sphone = $sgst = $span = "Not Available";
}
else
{
while ($row_seller = mysqli_fetch_array($run_query1))
{
$semail = $row_seller['seller_email'] . ",example#gmail.com";
}
}
$email = $semail;
$subject = "Order Details";
$message = 'You got a new Order!!! ";
require_once('mailer / class . phpmailer . php);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
You need to use addAddress method or addCC for add copy, like so
$mail->addAddress('mail#domain.com', 'NAME'); //add address
$mail->addCC('mail#domain.com', 'NAME'); / add copy
Github
I was sending emails from my website fine, but Email part was slow,
so I have decided to try and put this in a new thread,
And came up with this
public bool sendmail()
{
Thread T1 = new Thread(delegate()
{
MailMessage eMail = new MailMessage();
SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"]);
string EmailFromGCBS = (ConfigurationManager.AppSettings["EmailFROM"]);
eMail.From = new MailAddress(EmailFromGCBS);
eMail.To.Add(new MailAddress(emailTo));
eMail.Subject = emailSubject;
eMail.IsBodyHtml = isHtml;
eMail.Body = emailBody;
smtpClient.Send(eMail);
});
T1.Start();
return true;
}
the thread runs, but there is no emails sent any idea why this is?
When I am getting envelope by RequestStatus all recipients have same routing number. But I am sure and debug that provided different parameter for each recipient. And all recipients gets email in same time. How can I send envelope for each recipient according to RoutingOrder?
Sequential Signing (API) enabled for my account:
My examlple:
WebAPI.Recipient[] recipients = {new WebAPI.Recipient(), new WebAPI.Recipient()};
recipients[0].Email = "JohnDo#gmail.com";
recipients[0].UserName = "John Do";
recipients[0].Type = WebAPI.RecipientTypeCode.Signer;
recipients[0].ID = "2";
recipients[0].RoutingOrder = 2;
recipients[1].Email = "JohnDo2#gmail.com";
recipients[1].UserName = "John Do2";
recipients[1].Type = WebAPI.RecipientTypeCode.Signer;
recipients[1].ID = "1";
recipients[1].RoutingOrder = 1;
// Create envelope
WebAPI.Envelope envelope = new WebAPI.Envelope();
envelope.Subject = "Subject line mandatory!";
envelope.Recipients = recipients;
envelope.AccountId = APIAccountId;
// Create document
envelope.Documents = new WebAPI.Document[1];
WebAPI.Document doc = new WebAPI.Document();
doc.ID = "1";
doc.Name = "Picture PDF";
doc.TransformPdfFields = true;
doc.PDFBytes = Properties.Resources.test;
envelope.Documents[0] = doc;
// Create tab
WebAPI.Tab tab = new WebAPI.Tab();
WebAPI.AnchorTab anchorTab = new WebAPI.AnchorTab();
anchorTab.AnchorTabString = "Adobe";
anchorTab.IgnoreIfNotPresent = true;
anchorTab.IgnoreIfNotPresentSpecified = true;
tab.AnchorTabItem = anchorTab;
tab.CustomTabRequired = false;
tab.SenderRequired = false;
tab.Type = WebAPI.TabTypeCode.SignHere;
tab.DocumentID = "1";
tab.RecipientID = "1";
WebAPI.Tab tab2 = new WebAPI.Tab();
WebAPI.AnchorTab anchorTab2 = new WebAPI.AnchorTab();
anchorTab2.AnchorTabString = "CustomTag";
anchorTab2.IgnoreIfNotPresent = true;
anchorTab2.IgnoreIfNotPresentSpecified = true;
tab2.AnchorTabItem = anchorTab2;
tab2.Type = WebAPI.TabTypeCode.SignHere;
tab2.DocumentID = "1";
tab2.RecipientID = "2";
tab2.SenderRequired = false;
tab2.SharedTab = true;
tab2.TabLabel = "CustomTag";
tab2.Value = "Value2";
envelope.Tabs = new WebAPI.Tab[2];
envelope.Tabs[0] = tab;
envelope.Tabs[1] = tab2;
// Get results
WebAPI.EnvelopeStatus status = apiClient.CreateAndSendEnvelope(envelope);
Request to DocuSing SOAP API:
Request to DocuSing SOAP API
Problem resolved by adding option: for RoutingOrderSpecified = true each recipient ;
This code resolve problem for me:
recipients[0].RoutingOrderSpecified = true;
recipients[1].RoutingOrderSpecified = true;
I've been googling and trying different solutions for hours.
It works fine with GMail and Yahoo, but with Hotmail, it goes to the junk folder.
This is my code:
$sender = "xxx";
$sendername = "xxx";
$recipient = "xxx";
$recipientname = "xxx;
$pm->SetFrom($sender, $sendername);
$pm->AddReplyTo($sender, $sendername);
$pm->Sender = "xxx";
$pm->AddAddress($recipient, $recipientname);
$pm->IsSMTP();
$pm->SMTPAuth = true;
$pm->SMTPDebug = 2;
$pm->Host = "mail.xxx.com";
$pm->Port = 587;
$pm->Username = "xxx";
$pm->Password = "xxx";
$pm->Subject = "xxx news";
$pm->AddEmbeddedImage('forumLogo.png', 'logo');
$pm->Body = 'Here is my HTML content, not spammy.
</body>
</html>';
$pm->isHTML(true);
var_dump($pm->ErrorInfo);
if(!$pm->Send()) {
echo "Couldn't send: " . $pm->ErrorInfo;
}
else {
echo "Sent";
}
Hi i am trying to send an email using gmail credentials and calling an email template but it is throwing an exception that Failure sending mail
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential("ambarishkesavarapu#gmail.com", "xxxxxx");
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
message = new MailMessage();
message.Subject = "Visitor Arrived";
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
message.Body = "EmailTemplate.html";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.From = new MailAddress("ambarishkesavarapu#gmail.com");
message.To.Add(lblCPEmail.Text);
message.Priority = MailPriority.High;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpServer.Send(message);
Please help me out.
You have to use StreamReader to read from html file....and also set the MailMessage.BodyFormat property to MailFormat.Html
Use This:
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential("ambarishkesavarapu#gmail.com", "xxxxxx");
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
using (StreamReader reader = File.OpenText(htmlFilePath)) // Path to your
{ // HTML file
message = new MailMessage();
message.Subject = "Visitor Arrived";
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.From = new MailAddress("ambarishkesavarapu#gmail.com");
message.To.Add(lblCPEmail.Text);
message.Priority = MailPriority.High;
message.Body = reader.ReadToEnd(); // Load the content from your file...
//...
}
SmtpServer.Send(message);
Answer partially taken from Send a email with a HTML file as body (C#)
use port 465 instead
Port 465 is for smtps
SSL encryption is started automatically before any SMTP level communication.
Port 587 is for msa
It is almost like standard SMTP port. MSA should accept email after authentication (e.g. after SMTP AUTH). It helps to stop outgoing spam when netmasters of DUL ranges can block outgoing connections to SMTP port (port 25).
foreach (GnrDataMailInfo dmi in lstDMI)
{
MailMessage mail = new MailMessage();
mail.From = "youremail";
SmtpClient smtp = new SmtpClient();
smtp.Port = 25; // [1] port
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential(mail.From.ToString(), "password"); // [4] Added this.
smtp.EnableSsl = false;
smtp.Timeout = 20000;
smtp.Host = "yourhost";
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.HeadersEncoding = System.Text.Encoding.UTF8;
mail.Subject = dmi.Subject;
mail.To.Add(dmi.To);
mail.IsBodyHtml = true;
mail.Body = dmi.Body;
smtp.Send(mail);
}