How to send email to different recipient with a different set of data in SSIS or by SQL? - sql

Please suggest me how to achieved this:
The other table having set of data which I need to send:
Now by using SSIS we have to send the set of data to that email. In production I'm having 135 emails and have send them a separate data which contain their set of area.
#pp#gmial.cpm will get only data where subject is maths.
I have no idea to create variable of how to pass variable.
Can any one help me with this?

I use this method a lot for sending emails:
public static void SendEmail(List<string> to, string subject, string body, string filepathName = null)
{
using (MailMessage mail = new MailMessage())
{
string from = ConfigurationManager.AppSettings["EmailFrom"];
SmtpClient SmtpServer = new SmtpClient("your email server");
mail.From = new MailAddress(from);
foreach(string t in to)
mail.To.Add(new MailAddress(t));
mail.Subject = subject;
mail.ReplyToList.Add("your reply to email");
mail.IsBodyHtml = true;
mail.Body = body;
mail.Bcc.Add("enter your email if you want to be copied");
if (filepathName != null)
{
Attachment file;
file = new Attachment(filepathName);
mail.Attachments.Add(file);
}
SmtpServer.Port = 2525; //this is unique to you
SmtpServer.Credentials = new NetworkCredential(from, ConfigurationManager.AppSettings["EmailPassword"]);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
}
This won't completely solve your problem but will give you option of sending HTML emails straight from SSIS Script task.
You won't be able to use configuration manager, you will need to "hard code" that.

Related

Sending spark dataset as email

I have a spark dataset that needs to be sent as an attachment to an email.
I found the below link but it explains things in scala. Can someone help me with java code for sending the dataset as an attachment to an email?
sending-spark-dataframe-via-mail
Dataset<Row> finaldataset-> This is my dataset
Thanks in advance,
private void ConstructDataForEmail(Dataset<Row> datasetForEmail) {
try {
// Saving Dataset into CSV file into a single partition
datasetForEmail.repartition(1).write().
format("com.databricks.spark.csv").mode(SaveMode.Overwrite).option("header", true).save("/tmp/output");
//Getting Path of saved CSV file, as file is saved with name like part-0000-asgditda-yewd-yea-......csv
Optional<File> file = Arrays.stream(FileUtil.listFiles(new File("/tmp/output")).filter(fl -> fl.getName().endsWith(".csv")).findFirst();
String filePath = null;
if (file.isPresent())
filePath = file.get().getPath();
String subject = "Subject of the Email";
String emailBody = "Body for the Email";
String fileName = "Meaningful name to attached File";
//Method to send the email
sendMail(subject, emailBody, filePath, fileName);
} catch (Exception exp) {
LOG.info(" Error while preparing the data to send", exp);
}
}

sending email to multiple accounts using php ews

The below code is used for sending email using jamesiarmes/php-ews
in my application
$request = new \jamesiarmes\PhpEws\Request\CreateItemType();
$request->MessageDisposition = "SendOnly";
$request->SavedItemFolderId->DistinguishedFolderId->Id = "sentitems";
$request->Items->Message->ItemClass = "IPM.Note";
$request->Items->Message->Subject = "exchange new mail";
$request->Items->Message->Body->BodyType = 'HTML';
$request->Items->Message->Body->_ = "This is a test mail as a part of exchange settings set up ";
$request->Items->Message->ToRecipients->Mailbox->EmailAddress = "rejith.rj#pitsolutions.com";
$response = $this->app['ews']->CreateItem($request);
But the problem is I can add only one email address as recipient, how can I add multiple email addresses in ToRecipients?
I checked out the php-ews documentation. You can create an array with multiple recipients this way:
$toAddresses = array();
$toAddresses[0] = new EWSType_EmailAddressType();
$toAddresses[0]->EmailAddress = 'john.harris#domain.com';
$toAddresses[0]->Name = 'John Harris';
$toAddresses[1] = new EWSType_EmailAddressType();
$toAddresses[1]->EmailAddress = 'sara.smith#domain.com';
$toAddresses[1]->Name = 'Sara Smith';
And then add it to your object like this:
$request->Items->Message->ToRecipients = $toAddresses;
Try this and feedback me please.
Seems to me that your problem has not been solve yet?
Following works for me:
$toAddresses = array();
$toAddresses[0]="test#test.com";
$toAddresses[1]="test2#test.com";
$api = MailAPI::withUsernameAndPassword("server", "username", "password");
$message = new Type\MessageType();
$message->setBody('Some Text');
$message->setSubject('Test Subject');
$message->setToRecipients($toAddresses);

Adobe Echo Sign Sending PDF file

I am working on Adobe Echo sign,I have downloaded the sample code from their website, I am using this sample code for sendingdocument, it has some code missing in sendDocument method so I have changed it. It's giving SoapHeader Exception,with nothing in InnerException,
{"apiActionId=XHZI4WF4BV693YS"}
below is my code of sending document
public static void sendDocument(string apiKey, string fileName, string recipient)
{
ES = new EchoSignDocumentService16();
FileStream file = File.OpenRead(fileName);
secure.echosign.com.FileInfo[] fileInfos = new secure.echosign.com.FileInfo[1];
fileInfos[0] = new secure.echosign.com.FileInfo(fileName, null, file);
SenderInfo senderInfo = null;
string[] recipients = new string[1];
recipients[0] = recipient;
DocumentCreationInfo documentInfo = new DocumentCreationInfo(
recipients,
"Test from SOAP: " + fileName,
"This is neat.",
fileInfos,
SignatureType.ESIGN,
SignatureFlow.SENDER_SIGNATURE_NOT_REQUIRED
);
DocumentKey[] documentKeys;
senderInfo = new SenderInfo(recipient, "password", "APIKEY");
documentKeys = ES.sendDocument(apiKey, senderInfo, documentInfo);
Console.WriteLine("Document key is: " + documentKeys[0].documentKey);
}
its giving exception on this line
documentKeys = ES.sendDocument(apiKey, senderInfo, documentInfo);
Can anyone suggest some sample code of Adobe Echo Sign?
On the account page of your login there is an API log you can check. If you check the log entry for your request you may find more information there.
I can't see anything immediately wrong with your code however the EchoSign API guide says that the 'tos' field is deprecated and that the recipients field should be used instead. Helpfully this means you can't use the paramaterised constructor. Try creating your document creation info as such (this is C# but if you need Java it should be straightforward to figure out):
RecipientInfo[] recipientInfo = new RecipientInfo[1];
recipientInfo[0] = new RecipientInfo
{
email = "recipient",
role = RecipientRole.SIGNER,
roleSpecified = true
};
DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo
{
recipients = recipientInfo,
name = "Test from SOAP: " + fileName,
message = "This is neat.",
fileInfos = fileInfos,
signatureType = SignatureType.ESIGN,
signatureFlow = SignatureFlow.SENDER_SIGNATURE_NOT_REQUIRED
};
Note that when using the recipientInfo array it seems that the roleSpecified field must be set to true. This little field tripped me up for ages and I was receiving errors similar to yours.

Retrieving email-id from database and send mail to them

In yii i am creating sendemail functionality. I am using mailer extension and its working correctly after making all settings of SMTP. i had made method actionEmail in controller as-
public function actionEmail()
{
$model=new User;
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->IsSMTP();
$mailer->IsHTML(true);
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "ssl";
$mailer->Host = "smtp.gmail.com";
$mailer->Port = 465;
$mailer->CharSet = 'UTF-8';
$mailer->Username = "abc#gmail.com";
$mailer->Password = "abc";
$mailer->From = "xyz#gmail.com";
$mailer->FromName = "Balaee.com";
$mailer->AddAddress('shilpa.kirad#shailani.com');
$mailer->Subject = "welcome to Balaee";
$mailer->IsHTML(true);
// $html = $this->renderPartial('myview',array('content'=>'Hello World'),true);
$mailer->Body = "Welcomeclick on link for other detail ".$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if($mailer->Send()) {
echo "Please check mail";
//Yii::app()->user->setFlash('register','Thank you for contacting us. We will respond to you as soon as possible.');
// $this->refresh();
}
else {
echo "Fail to send your message!";
}
}
This method is implementing correctly.It is sending mail to address which is mentioned in mailer->AddAdress.But now i want to retrive email id's from database corresponding to specific user's id and send mail to him. i.e.I dont want to insert hard coded value for this field. So how can i do this. Please help me.
for fetch use id of user to get email address as
$user_model=User::model()->findByPk($id);
and set in email as
$mailer->AddAddress($user_model->email_id);
where id and email_id are the table column name.
check other ways .
http://www.yiiframework.com/doc/guide/1.1/en/database.dao
For this to be done, you can fetch email id from database using following query:
$email = SELECT email FROM USER WHERE user_id = "X";
Here X is user_id of user whom you want to send email.
And provide this $email in the receipient's email field. Thanks.

CDO.Message giving "Access denied" on Windows Server 2008

I have a Classic ASP page that creates a CDO.Message object to send email. The code works on Window Server 2003 but not 2008. On 2008 an "Access is denied" error gets thrown. Here is a simple test page I wrote to diagnose the problem. How can I get this to work on Windows Server 2008?
dim myMail
Set myMail=CreateObject("CDO.Message")
If Err.Number <> 0 Then
Response.Write ("Error Occurred: ")
Response.Write (Err.Description)
Else
Response.Write ("CDO.Message was created")
myMail.Subject="Sending email with CDO"
myMail.From="sender#mycompany.com"
myMail.To="recipient#mycompany.com"
myMail.TextBody="This is a message."
myMail.Send
set myMail=nothing
End If
I never got the CDO.Message object to work on Windows Server 2008. However, I found a workaround. I wrote an email class that works on Windows Server 2008. Hope this helps someone else.
[ComVisible(true)]
public class Email
{
public bool SendEmail(string strTo, string strFrom , string strSubject, string strBody)
{
bool result = false;
try
{
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient("smtp.mycompany.com");
List<string> to = recipientList(strTo);
foreach (string item in to)
{
message.To.Add(new MailAddress(item));
}
message.From = new MailAddress(strFrom);
message.Subject = strSubject;
message.Body = strBody;
client.Send(message);
result = true;
}
catch
{
result = false;
throw;
}
return result;
}
private List<string> recipientList(string strTo)
{
List<string> result = new List<string>();
string[] emailAddresses = strTo.Split(new Char[]{',',';'});
foreach (string email in emailAddresses)
{
result.Add(email.Trim());
}
return result;
}
}
As long as you're using the Microsoft SMTP server(1) you can use the IIS Metabase Explorer to give the IIS_USRS group(2) read read access to the /LM/SmtpSvc/ and /LM/SmtpSvc/1/ nodes in the IIS Metabase.
Unfortunately this solution doesn't apply to Windows 7. Microsoft does not ship an SMTP server with Windows 7, making it very difficult to get around this problem without refactoring your code.
(1) See http://www.itsolutionskb.com/2008/11/installing-and-configuring-windows-server-2008-smtp-server
(2) See http://blogs.msdn.com/b/akashb/archive/2010/05/24/error-cdo-message-1-0x80040220-the-quot-sendusing-quot-configuration-value-is-invalid-on-iis-7-5.aspx