Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all 29741 articles
Browse latest View live

Laravel "universal to" in development vs production

$
0
0

I'm working with a Laravel 5.2 application. In my development and staging environments, I'd like to make use of the "Universal To" mail config option described in the docs. A universal to in development environments ensures all emails go to that address, instead of out to real customers/clients/whatever.

I can't work out how to specify this differently in production though. In production there should be no universal to - emails should go out to real addresses.

The standard approach of using different env() values does not seem to work. For example:

config/mail.php:

'to' => [
    'address'   => env('UNIVERSAL_TO', false)
],

development .env:

UNIVERSAL_TO=my-testing-address@somewhere.com

This works fine - all emails go to the specified UNIVERSAL_TO, as expected. But if I change that to what I will want in production, eg:

production .env

UNIVERSAL_TO=

(or ='', or =false, or simply omitting this completely), sending any mail fails with (in storage/laravel.log):

local.ERROR: exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [] does not comply with RFC 2822, 3.6.2.' in path/to/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php:348

config/mail.php is just returning an array, so I suppose I could instead set it as a variable and then depending on environment append the 'to' to it, like so:

$return = [ ... normal mail config array ... ];

if (!\App::environment('production')) {
    $return['to'] => [
        'address' => 'my-testing-address@somewhere.com'
    ];
}

return $return;

But this seems a little ... hacky. Is there a better way?


Validate subject line of an email message

$
0
0

Some characters are invalid in an email subject and will result in failure, for example carriage return. I accept subject line as an input.

Is there a definitive description of what makes a valid email Subject? I've looked in the what I think is the correct RFC spec and can't find any.

Are there any .Net libraries that will validate/sanitise an email subject line? Particularly is there anything in the core libraries or in MailKit?

Sending emails to addresses with non-ASCII characters

$
0
0

We have a small mailing web service, cause not every app can access the SMTP server. Now This evening, the web service couldn't send a mail because the receiving mail address contained some more complex characters, resulting in a The client or server is only configured for E-mail addresses with ASCII local-parts error.

After googling for a solution, I found out that you should set the DeliveryFormat to International.

I've implemented this, but I still keep getting the same error. Adding a watch also tells me that smtp.IsUnicodeSupported is still false

This is the code at the moment:

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();   
mail.Subject = mailSubject;
mail.Body = mailBody;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal;
mail.HeadersEncoding = Encoding.UTF8;
System.Net.Mail.SmtpClient smtp  = new System.Net.Mail.SmtpClient("smtp.mydomain.net");
smtp.DeliveryFormat = SmtpDeliveryFormat.International;
smtp.Send(mail);

The property smtp.transport.ServerSupportsEai is also still false, but it doesn't seem that contact with the SMTP server has been established at that point.

What else can I do to force the SMTP client to send the mail? Is it even solvable at the application-end?

YITH Woocommerce Request A Quote Premium

$
0
0

I am using WordPress 5.2 with the plugin YITH Woocommerce Request A Quote Premium.

Whenever I hit “Send Your Request” the page refreshes and nothing happens. No email is sent and when I enabled debug in wp-config I get this:

Notice: is_main_query was called incorrectly. In pre_get_posts, use the WP_Query->is_main_query() method,

Notice: id was called incorrectly. Product properties should not be accessed directly

Any help or advice would be greatly appreciated!

Razor View Page as Email Template

$
0
0

I have designed an Email Template from Razor Syntax. When I send this template as Email using C# code and SMTP protocol, I get bare Razor and HTML markups as Email Body. Am I wrong in this approach? Are Razor Pages allowed as Email Template?

Here is my Page

@inherits ViewPage
@{
Layout = "_Layout";
ViewBag.Title = "";
}
<div class="container w-420 p-15 bg-white mt-40">
<div style="border-top:3px solid #22BCE5">&nbsp;</div>
<span style="font-family:Arial;font-size:10pt">
    Hello <b>{UserName}</b>,<br /><br />
    Thanks for Registering to XYZ Portal<br /><br />
    <a style="color:#22BCE5" href="{Url}">Click to Confirm Email</a><br />

    <br /><br />
    Thanks<br />
    Admin (XYZ)
</span>

Update..

 using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/ContentPages/EmailConfTemplate.cshtml")))
  {
     body = reader.ReadToEnd();
     //Replace UserName and Other variables available in body Stream
     body = body.Replace("{UserName}", FirstName);

  }

Later On I am replacing the SMTP Code as ..

  MailMessage message = new MailMessage(
    ApplicationWideData.fromEmailId, // From field
    ToEmailId, // Recipient field
    "Click On HyperLink To Verify Email Id", // Subject of the email message
    body
   );

How can I transform a PHPMailer connection to Laravel .env?

$
0
0

I have a situation where an app is sending its mails with PHPMailer and next configuration:

      $mail->isSMTP();
      $mail->Host     = 'myhost.dev';
      $mail->SMTPAuth = false;

      $mail->setFrom($from, $from_name);
      $mail->addAddress($to, $to_name);
      if ($replyTo != '') $mail->addReplyTo($replyTo, $replyToName);
      $mail->isHTML(true);
      $mail->CharSet = 'UTF-8';
      $mail->Subject = $subject;
      $mail->Body    = $body;

As you can see, SMTP server doesn't require authentication and all is working ok. That's all data I have about the mail server. Now, I need to make the same thing but instead of using PHPMailer I want to implement the sending method of Laravel, but I don't have any authentication credential for setting my .env file.

How can I pass the same configuration to my Laravel development? I've tried many combinations but nothing happens. This was the last one:

MAIL_DRIVER=smtp
MAIL_HOST=myhost.dev
MAIL_PORT=25
MAIL_USERNAME=no-reply@host.com
MAIL_PASSWORD=''
MAIL_ENCRYPTION=''

How to format DKIM Header and body?

$
0
0

I've done a question about this before, but still do not understand what to do.

I need to make canonicalized header and body for a email. I've read this piece of documentation lots of times. Could someone make a example, because I cannot wrap my head around this:

3.4.1. The "simple" Header Canonicalization Algorithm

The "simple" header canonicalization algorithm does not change header fields in any way. Header fields MUST be presented to the signing or verification algorithm exactly as they are in the message being signed or verified. In particular, header field names MUST NOT be case folded and whitespace MUST NOT be changed.

3.4.2. The "relaxed" Header Canonicalization Algorithm

The "relaxed" header canonicalization algorithm MUST apply the following steps in order:

  • Convert all header field names (not the header field values) to lowercase. For example, convert "SUBJect: AbC" to "subject: AbC".

  • Unfold all header field continuation lines as described in [RFC5322]; in particular, lines with terminators embedded in continued header field values (that is, CRLF sequences followed by WSP) MUST be interpreted without the CRLF. Implementations MUST NOT remove the CRLF at the end of the header field value.

  • Convert all sequences of one or more WSP characters to a single SP character. WSP characters here include those before and after a line folding boundary.

  • Delete all WSP characters at the end of each unfolded header field value.

  • Delete any WSP characters remaining before and after the colon separating the header field name from the header field value. The colon separator MUST be retained.

3.4.3. The "simple" Body Canonicalization Algorithm

The "simple" body canonicalization algorithm ignores all empty lines at the end of the message body. An empty line is a line of zero length after removal of the line terminator. If there is no body or no trailing CRLF on the message body, a CRLF is added. It makes no other changes to the message body. In more formal terms, the "simple" body canonicalization algorithm converts "*CRLF" at the end of the body to a single "CRLF".

Note that a completely empty or missing body is canonicalized as a single "CRLF"; that is, the canonicalized length will be 2 octets.

The SHA-1 value (in base64) for an empty body (canonicalized to a "CRLF") is:

uoq1oCgLlTqpdDX/iUbLy7J1Wic=

The SHA-256 value is:

frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN/XKdLCPjaYaY=

3.4.4. The "relaxed" Body Canonicalization Algorithm

The "relaxed" body canonicalization algorithm MUST apply the following steps (1) and (2) in order:

  1. Reduce whitespace:

    • Ignore all whitespace at the end of lines. Implementations MUST NOT remove the CRLF at the end of the line.

    • Reduce all sequences of WSP within a line to a single SP character.

  2. Ignore all empty lines at the end of the message body. "Empty line" is defined in Section 3.4.3. If the body is non-empty but does not end with a CRLF, a CRLF is added. (For email, this is only possible when using extensions to SMTP or non-SMTP transport mechanisms.)

The SHA-1 value (in base64) for an empty body (canonicalized to a null input) is:

2jmj7l5rSw0yVb/vlWAYkK/YBwk=

The SHA-256 value is:

47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=

3.4.5. Canonicalization Examples (INFORMATIVE)

In the following examples, actual whitespace is used only for clarity. The actual input and output text is designated using bracketed descriptors: "<SP>" for a space character, "<HTAB>" for a tab character, and "<CRLF>" for a carriage-return/line-feed sequence. For example, "X <SP> Y" and "X<SP>Y" represent the same three characters.

Example 1: A message reading:

A: <SP> X <CRLF>
B <SP> : <SP> Y <HTAB><CRLF>
                <HTAB> Z <SP><SP><CRLF>
<CRLF>
<SP> C <SP><CRLF>
D <SP><HTAB><SP> E <CRLF>
<CRLF>
<CRLF>

when canonicalized using relaxed canonicalization for both header and body results in a header reading:

a:X <CRLF>
b:Y <SP> Z <CRLF>

and a body reading:

<SP> C <CRLF>
D <SP> E <CRLF>

Example 2: The same message canonicalized using simple canonicalization for both header and body results in a header reading:

A: <SP> X <CRLF>
B <SP> : <SP> Y <HTAB><CRLF>
       <HTAB> Z <SP><SP><CRLF>

and a body reading:

<SP> C <SP><CRLF>
D <SP><HTAB><SP> E <CRLF>

Example 3: When processed using relaxed header canonicalization and simple body canonicalization, the canonicalized version has a header of:

a:X <CRLF>
b:Y <SP> Z <CRLF>

and a body reading:

<SP> C <SP><CRLF>
D <SP><HTAB><SP> E <CRLF>

Gmail Email Forwarder [closed]

$
0
0

New to programming and would really appreciate some help on this school project. I'm trying to build an application that automates the following sequence of events:

  1. Takes an input from sender via receiving an email
  2. Sends this input to a specified list of intermediary mailboxes
  3. In those intermediary mailboxes, forwards the input email to a specified list of addresses

All mailboxes involved are hosted by G Suite. In case you're wondering, we're creating this to bypass mailing list restrictions, since only the member of a mailing list can post to a mailing list. If I want to send something to list B, I must find someone in list B to send it for me.

How should we go about this? Will this be a PHP script? Will we need Google authentication at all? New to this and don't know anything so any help is appreciated. Thank you so much!


How to get mail from toMail method which is in PasswordResetNotification in Laravel 6.2

$
0
0

I'm using Laravel 6.2. How can I get the reset mail from password reset form inside PasswordResetNotification's toMail method? There I have a url to redirect , like below. . .

public function toMail($notifiable) {
    $url_to_reset = "http://localhost:3000/admin/reset-password/client-mail=" . $user_mail . "&token=" . $this->token;
    return (new MailMessage)->from('mymail@gmail.com');
}

I want to get $user_mail. How can I get it? Thank you.

How email service providers decide whether to block ip address or domain name?

$
0
0

As i know there are two types of blacklist; domain and ip based blacklists. How email service providers(gmail,hotmail,yandex) decide whether to add Ip address to blacklist not domain or vice versa?

Let's suppose that I have configured a MTA for example.com domain and start sending spams from that domain. So how and when the receiving mail server decide to block mta ip address either example.com domain?

Sending mail per outlook with funcitional mail / change user in python

$
0
0

I try to send an e-mail in python with outlook, right now this is working:

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = test@google.de
attachment  = 'Test.xlsx'
mail.Attachments.Add(attachment)
mail.Send()   

How can I change this line of codes, that it is send out with my functional postfach so that the sending adress changes from: PV8@test.com to functional@test.com, I am using outlook.

Random email addresses being signed up to my website

$
0
0

Over the past few months random email addresses, some of which are on known spam lists, have been added at the rate of 2 or 3 a day to my website.

I know they aren't real humans - for a start the website is in a very narrow geographical area, and many of these emails are clearly from a different country, others are info@ addresses that appear to have been harvested from a website, rather than something a human would use to sign up to a site.

What I can't work out is, what are reasons for somebody doing this? I can't see any benefit to an external party beyond being vaguely destructive. (I don't want to link to the site here, it's just a textbox where you enter email and press join).

These emails are never verified - my question isn't about how to prevent this, but what are some valid reasons why somebody might do this. I think it's important to understand why malicious users do what they do.

.NET Outlook Default folder free space (Quota Information)

$
0
0

Is there any way to read via Microsoft.Office.Interop free space left in default Mailbox ?

(So the same info what is displayed in Outlook's down left corner - as shown below)

enter image description here

Spring Boot email sending throws SocketTimeoutException: Read timed out

$
0
0

I've already researched the topic for a few days but none of the answers I found online did the trick for me.

Context: I've got a Spring Boot web application which sends automatic emails notifications using Java Mail API and Spring Boot Starter Mail.

It is using GMail SMTP server with a GSuite account. I recently upgraded to use Spring 5.0.6 and Spring Boot 2.0.2 and the email sending stopped working.

A few clues:

  • the Java code sending the email is the same as before
  • Gmail SMTP still works correctly (from another VM using older version of the application with the same settings and authentication, the emails are sent properly).
  • unless I am missing something, the application configuration remains the same as before

The things that have changed:

  • upgrade to Spring 5.0.6
  • upgrade to Spring Boot 2.0.2
  • changes in many places in the Java code to match this upgrades and add features in other parts of the app
  • The IP address of the VM is different than before (AWS EC2 instance)

Here are the relevant dependencies in pom.xml :

<!-- https://mvnrepository.com/artifact/javax.mail/javax.mail-api -->
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>javax.mail-api</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>

Here is the application.yml relevant to Spring mail:

spring:
  mail:
    host: ${FT_MAIL_SMTP_HOST}
     port: ${FT_MAIL_SMTP_PORT}
     username: ${FT_MAIL_SMTP_USERNAME}
     password: ${FT_MAIL_SMTP_PASSWORD}
     debug: false
     properties:
       mail:
         smtp:
           starttls:
             enable: ${FT_MAIL_SMTP_STARTTLS}
             required: ${FT_MAIL_SMTP_TLSREQUIRED}
           auth: ${FT_MAIL_SMTP_AUTH}
           connectiontimeout: ${FT_MAIL_SMTP_CONN_TIMEOUT}
           timeout: ${FT_MAIL_SMTP_TIMEOUT}
           writetimeout: ${FT_MAIL_SMTP_WRITE_TIMEOUT}

These variables are defined in the environment:

FT_MAIL_SMTP_HOST=smtp.gmail.com
FT_MAIL_SMTP_PORT=587
FT_MAIL_SMTP_USERNAME=myaccount@myapp.com
FT_MAIL_SMTP_PASSWORD=mypassword

FT_MAIL_SMTP_STARTTLS=true
FT_MAIL_SMTP_TLSREQUIRED=true
FT_MAIL_SMTP_AUTH=true
FT_MAIL_SMTP_CONN_TIMEOUT=5000
FT_MAIL_SMTP_TIMEOUT=5000
FT_MAIL_SMTP_WRITE_TIMEOUT=5000

Here is the Spring @Service used to send the email (unchanged):

@Service
public class EmailServiceImpl {

@Autowired
public JavaMailSender emailSender;

@Autowired
private SpringTemplateEngine templateEngine;

@Value("${myapp.mail.from}")
private String fromAddress;

@Value("${myapp.mail.replyto}")
private String replyToAddress;

public void sendTemplatedMessage(String template, String to, String subject, Map<String, Object> model) throws MailException, MessagingException {  
    sendTemplatedMessage(template, to, fromAddress, replyToAddress, subject, model);
}

public void sendTemplatedMessage(String template, String to, String from, String subject, Map<String, Object> model) throws MailException, MessagingException { 
    sendTemplatedMessage(template, to, from, replyToAddress, subject, model);
}

private void sendTemplatedMessage(String template, String to, String from, String replyTo, String subject, Map<String, Object> model) throws MailException, MessagingException {    

    MimeMessage message = emailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(message,
            MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
            StandardCharsets.UTF_8.name());

    //helper.addAttachment("logo.png", new ClassPathResource("memorynotfound-logo.png"));
    Context context = new Context();
    context.setVariables(model);
    String html = templateEngine.process(template, context);

    helper.setTo(to);
    helper.setFrom(from);
    helper.setReplyTo(from);
    helper.setSubject(subject);
    helper.setText(html, true);

    emailSender.send(message);
}

public void sendSimpleMessage(String to, String from, String subject, String text) {
    try {           
        SimpleMailMessage message = new SimpleMailMessage(); 
        message.setTo(to);
        message.setFrom(from);
        message.setSubject(subject); 
        message.setText(text);
        emailSender.send(message);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

Now here is the error I get when trying to send an email:

04:42:19.900 [https-jsse-nio-443-exec-3] ERROR c.f.controller.StayController - Could not send Guest confirmation email to gfgorostidi@protonmail.com
org.springframework.mail.MailSendException: Failed to close server connection after message sending; nested exception is javax.mail.MessagingException: Exception reading response;
  nested exception is:
 java.net.SocketTimeoutException: Read timed out
 at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:482)
 at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:359)
 at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:354)
 at com.myapp.util.EmailServiceImpl.sendTemplatedMessage(EmailServiceImpl.java:61)
 at com.myapp.util.EmailServiceImpl.sendTemplatedMessage(EmailServiceImpl.java:35)
 at com.myapp.controller.StayController.sendConfirmEmailToGuest(StayController.java:437)
 at com.myapp.controller.StayController.saveStay(StayController.java:383)
 at com.myapp.controller.StayController.createStay(StayController.java:163)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 ......
 ......
 ......
 at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: javax.mail.MessagingException: Exception reading response;
  nested exception is:
 java.net.SocketTimeoutException: Read timed out
 at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2202)
 at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1212)
 at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:473)
 ... 104 more
Caused by: java.net.SocketTimeoutException: Read timed out
 at java.base/java.net.SocketInputStream.socketRead0(Native Method)
 at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
 at java.base/java.net.SocketInputStream.read(SocketInputStream.java:171)
 at java.base/java.net.SocketInputStream.read(SocketInputStream.java:141)
 at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:425)
 at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:65)
 at java.base/sun.security.ssl.SSLSocketImpl.bytesInCompletePacket(SSLSocketImpl.java:918)
 at java.base/sun.security.ssl.AppInputStream.read(AppInputStream.java:144)
 at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
 at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
 at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:271)
 at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:89)
 at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2182)
 ... 106 more
org.springframework.mail.MailSendException: Failed to close server connection after message sending; nested exception is javax.mail.MessagingException: Exception reading response;
  nested exception is:
 java.net.SocketTimeoutException: Read timed out
 at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:482)
 at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:359)
 at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:354)
 at com.myapp.util.EmailServiceImpl.sendTemplatedMessage(EmailServiceImpl.java:61)
 at com.myapp.util.EmailServiceImpl.sendTemplatedMessage(EmailServiceImpl.java:35)
 at com.myapp.controller.StayController.sendConfirmEmailToGuest(StayController.java:437)
 at com.myapp.controller.StayController.saveStay(StayController.java:383)
 at com.myapp.controller.StayController.createStay(StayController.java:163)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 ......
 ......
 ......
 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468)
 at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: javax.mail.MessagingException: Exception reading response;
  nested exception is:
 java.net.SocketTimeoutException: Read timed out
 at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2202)
 at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1212)
 at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:473)
 ... 104 more
Caused by: java.net.SocketTimeoutException: Read timed out
 at java.base/java.net.SocketInputStream.socketRead0(Native Method)
 at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
 at java.base/java.net.SocketInputStream.read(SocketInputStream.java:171)
 at java.base/java.net.SocketInputStream.read(SocketInputStream.java:141)
 at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:425)
 at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:65)
 at java.base/sun.security.ssl.SSLSocketImpl.bytesInCompletePacket(SSLSocketImpl.java:918)
 at java.base/sun.security.ssl.AppInputStream.read(AppInputStream.java:144)
 at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
 at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
 at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:271)
 at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:89)
 at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2182)
 ... 106 more

I have tried setting an incorrect SMTP server or bad credentials and this made the connection fail, so I assumed the server and credentials are correct as they are, and the error happens after a successful connection.

The account used hasn't reached its limit, as another VM uses the same credentials and sends emails without problem.

I've tried changing "Start TLS" settings to false and use port 465 instead, but this isn't working either.

Any help is appreciated !! Thanks in advance!

woocommerce custom email templates php

$
0
0

I am stuck in resolving custom email templates to woocomerce. I read dozens of forums (Customize WooCommerce order email), and I do have my the custom email template in the right folder, but woocommerce does send the original one. I also tried to modify the plain email templates in the woocommerce folder, but it still didn't work. I don't understand from where can it take such a text, when I have deleted it from all occurences.

The path to my custom email template: mytheme/resource/woocommerce/emails, I tried also mytheme/woocommerce/emails

The path to the original templates: woocommerce/templates/emails and woocommerce/templates/emails/plain

I tried modifying all of them. In wp admin, I see the right, modified email templates, but still the system sends the original one.

Thanks in advance for any response!


unable to send mail to my office account in Python

$
0
0

I am trying to mail to my office account, 'wipro.com', but could not with the below error.

import smtplib

mailserver = smtplib.SMTP('smtp.office365.com',587)
mailserver.ehlo()
mailserver.starttls()
mailserver.login('wwww@wipro.com', 'zzzz')
mailserver.sendmail('aaaa@wipro.com','python email')
mailserver.quit()

SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful [BM1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM]')

Handling connection with imaplib while using context manager

$
0
0

I am trying to connect to mail server using python's imaplib . Here is how my code currently stands:

@contextlib.contextmanager
def get_connection(username: str, password: str, host=GMAIL_IMAP_HOST, port=GMAIL_IMAP_PORT):
    '''
    ARGS:
        username: User username
        password: User Password
        host: IMAP server address
        post: IMAP port

    Connect to IMAP server and close connection
    '''

    conn = None

    try:
        conn = imaplib.IMAP4_SSL(host, port)
        conn.login(username, password)
        response, _ = conn.select('INBOX')

        if response != 'OK':
            raise MyException('An error occurred authenticating - {}'.format(response))

        yield conn
    finally:
        if conn is not None:
            conn.close()   # <- Check if mailbox is selected
            conn.logout()  # <- Check if logged in

How can I check if the user is authenticated and if a mailbox is selected?

SMTP mail server (sendgrid) error on submission

$
0
0

I have an app that sends an email with image attachments thru an SMTP server (sendgrid).

When the application launches it initializes a Socket connection and authenticates the user(application. I see the following message returned from Sendgrid

SG ESMTP service ready at<foo..sendgrid.net

and I also get a successful authentication returned.

However, on sending an email I get the following 3 errors:

error 1 550  Unauthenticated senders not allowed
error 2 503 Must have sender before recipient
error 3 503 Must have valid receiver and originator

So this suggests to me that I must change the order of sender and recipient in my SMTP module. Internally I am taking an incoming ByteArray and converting to base64 string in order to send emails with attached files.

So how would I change the following code excerpt?

        writeUTFBytes ("MAIL FROM: <"+pFrom+">\r\n");
        writeUTFBytes ("RCPT TO: <"+pDest+">\r\n");
        writeUTFBytes ("DATA\r\n");
        writeUTFBytes ("From: "+pFrom+"\r\n");
        writeUTFBytes ("To: "+pDest+"\r\n");

This is the entire class I am using. I call authenticate just once after the class is initialized and then sendAttachedMail when sending email with image attachments. And when testing using a local SMTP server WITHOUT authentication, everything works fine(emails and image attachments sent)

package org.bytearray.smtp.mailer
{
    import flash.events.ProgressEvent;
    import flash.net.Socket;
    import flash.utils.ByteArray;
    import flash.utils.getTimer;

    import org.bytearray.smtp.crypto.MD5;
    import org.bytearray.smtp.encoding.Base64;
    import org.bytearray.smtp.events.SMTPEvent;
    import org.bytearray.smtp.infos.SMTPInfos;

    public class SMTPMailer extends Socket 
    {
        private var sHost:String;
        private var buffer:Array = new Array();

        // regexp pattern
        private var reg:RegExp = /^\d{3}/img;

        // PNG, JPEG header values
        private static const PNG:Number = 0x89504E47;
        private static const JPEG:Number = 0xFFD8;

        // common SMTP server response codes
        // other codes could be added to add fonctionalities and more events
        private static const ACTION_OK:Number = 0xFA;
        private static const AUTHENTICATED:Number = 0xEB;
        private static const DISCONNECTED:Number = 0xDD;
        private static const READY:Number = 0xDC;
        private static const DATA:Number = 0x162;
        private static const BAD_SEQUENCE:Number = 0x1F7;

        public function SMTPMailer ( pHost:String, pPort:int) 
        {
            super ( pHost, pPort );         
            sHost = pHost;
            addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler,false,0,true);
        }

        public function reset():void{
            removeEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
        }

        /*
        * This method lets you authenticate, just pass a login and password
        */
        public function authenticate ( pLogin:String, pPass:String ):void
        {
            writeUTFBytes ("EHLO "+sHost+"\r\n");
            writeUTFBytes ("AUTH LOGIN\r\n");
            writeUTFBytes (Base64.encode64String (pLogin)+"\r\n");
            writeUTFBytes (Base64.encode64String (pPass)+"\r\n");
            flush();
        }

        /*
        * This method is used to send emails with attached files and HTML 
        * takes an incoming Bytearray and convert it to base64 string
        * for instance pass a JPEG ByteArray stream to get a picture attached in the mail ;)
        */
        public function sendAttachedMail ( pFrom:String, pDest:String, pSubject:String, pMess:String, pByteArray:ByteArray, pFileName:String ) :void
        {
            try {

                writeUTFBytes ("HELO "+sHost+"\r\n");
                writeUTFBytes ("MAIL FROM: <"+pFrom+">\r\n");
                writeUTFBytes ("RCPT TO: <"+pDest+">\r\n");
                writeUTFBytes ("DATA\r\n");
                writeUTFBytes ("From: "+pFrom+"\r\n");
                writeUTFBytes ("To: "+pDest+"\r\n");
                writeUTFBytes ("Date : "+new Date().toString()+"\r\n");
                writeUTFBytes ("Subject: "+pSubject+"\r\n");
                writeUTFBytes ("Mime-Version: 1.0\r\n");

                var md5Boundary:String = MD5.hash ( String ( getTimer() ) );

                writeUTFBytes ("Content-Type: multipart/mixed; boundary=------------"+md5Boundary+"\r\n");
                writeUTFBytes("\r\n");
                writeUTFBytes ("This is a multi-part message in MIME format.\r\n");
                writeUTFBytes ("--------------"+md5Boundary+"\r\n");
                writeUTFBytes ("Content-Type: text/html; charset=UTF-8; format=flowed\r\n");
                writeUTFBytes("\r\n");
                writeUTFBytes (pMess+"\r\n");
                writeUTFBytes ("--------------"+md5Boundary+"\r\n");
                writeUTFBytes ( readHeader (pByteArray, pFileName) );
                writeUTFBytes ("Content-Transfer-Encoding: base64\r\n");
                writeUTFBytes ("\r\n");

                var base64String:String = Base64.encode64 ( pByteArray, true );

                writeUTFBytes ( base64String+"\r\n");
                writeUTFBytes ("--------------"+md5Boundary+"-\r\n");
                writeUTFBytes (".\r\n");
                flush();

            } catch ( pError:Error )
            {
                trace("Error : Socket error, please check the sendAttachedMail() method parameters");
                trace("Arguments : " + arguments );     
            }
        }

        /*
        * This method is used to send HTML emails
        * just pass the HTML string to pMess
        */
        public function sendHTMLMail ( pFrom:String, pDest:String, pSubject:String, pMess:String ):void
        {
            try 
            {           
                writeUTFBytes ("HELO "+sHost+"\r\n");
                writeUTFBytes ("MAIL FROM: <"+pFrom+">\r\n");
                writeUTFBytes ("RCPT TO: <"+pDest+">\r\n");
                writeUTFBytes ("DATA\r\n");
                writeUTFBytes ("From: "+pFrom+"\r\n");
                writeUTFBytes ("To: "+pDest+"\r\n");
                writeUTFBytes ("Subject: "+pSubject+"\r\n");
                writeUTFBytes ("Mime-Version: 1.0\r\n");
                writeUTFBytes ("Content-Type: text/html; charset=UTF-8; format=flowed\r\n");
                writeUTFBytes("\r\n");
                writeUTFBytes (pMess+"\r\n");
                writeUTFBytes (".\r\n");
                flush();

            } catch ( pError:Error )
            {   
                trace("Error : Socket error, please check the sendHTMLMail() method parameters");
                trace("Arguments : " + arguments ); 
            }
        }

        /*
        * This method automatically detects the header of the binary stream and returns appropriate headers (jpg, png)
        * classic application/octet-stream content type is added for different kind of files
        */
        private function readHeader ( pByteArray:ByteArray, pFileName:String ):String 
        {
            pByteArray.position = 0;

            var sOutput:String = null;

            if ( pByteArray.readUnsignedInt () == SMTPMailer.PNG ) 
            {
                sOutput = "Content-Type: image/png; name="+pFileName+"\r\n";
                sOutput += "Content-Disposition: attachment filename="+pFileName+"\r\n";
                return sOutput; 
            }

            pByteArray.position = 0;

            if ( pByteArray.readUnsignedShort() == SMTPMailer.JPEG ) 
            {
                sOutput = "Content-Type: image/jpeg; name="+pFileName+"\r\n";
                sOutput += "Content-Disposition: attachment filename="+pFileName+"\r\n";
                return sOutput; 
            }

            sOutput = "Content-Type: application/octet-stream; name="+pFileName+"\r\n";
            sOutput += "Content-Disposition: attachment filename="+pFileName+"\r\n";

            return sOutput;
        }

        // check SMTP response and dispatch proper events
        // Keep in mind SMTP servers can have different result messages the detection can be modified to match some specific SMTP servers
        private function socketDataHandler ( pEvt:ProgressEvent ):void
        {
            var response:String = pEvt.target.readUTFBytes ( pEvt.target.bytesAvailable );
            buffer.length = 0;
            var result:Array = reg.exec(response);

            while (result != null)
            {   
                buffer.push (result[0]);
                result = reg.exec(response);
            }

            var smtpReturn:Number = buffer[buffer.length-1];
            var smtpInfos:SMTPInfos = new SMTPInfos ( smtpReturn, response );

            if ( smtpReturn == SMTPMailer.READY ) 
                dispatchEvent ( new SMTPEvent ( SMTPEvent.CONNECTED, smtpInfos ) );

            else if ( smtpReturn == SMTPMailer.ACTION_OK && (response.toLowerCase().indexOf ("queued") != -1 || response.toLowerCase().indexOf ("accepted") != -1 ||
                    response.toLowerCase().indexOf ("qp") != -1) ) dispatchEvent ( new SMTPEvent ( SMTPEvent.MAIL_SENT, smtpInfos ) );
            else if ( smtpReturn == SMTPMailer.AUTHENTICATED ) 
                dispatchEvent ( new SMTPEvent ( SMTPEvent.AUTHENTICATED, smtpInfos ) );
            else if ( smtpReturn == SMTPMailer.DISCONNECTED ) 
                dispatchEvent ( new SMTPEvent ( SMTPEvent.DISCONNECTED, smtpInfos ) );
            else if ( smtpReturn == SMTPMailer.BAD_SEQUENCE ) 
                dispatchEvent ( new SMTPEvent ( SMTPEvent.BAD_SEQUENCE, smtpInfos ) );
            else if ( smtpReturn != SMTPMailer.DATA ) 
                dispatchEvent ( new SMTPEvent ( SMTPEvent.MAIL_ERROR, smtpInfos ) );    
        }
    }
}

iOS how to make email address in a label clickable

$
0
0

I believe this question has been asked and answered before, but I couldn't find it. I see an answer pointing to Fancy Label and Three20, but they are not quite what I want, or probably I missed some points.

Basically, I want get app users' feedback, so I will write in a big label, like

blah blah, email me at xxxxxx@gmail.com, and blah blah more.

I want the email address clickable, and open email composer so that users can edit and send.

That's all I need. How to get it? Thanks.

Is there a way to integrate gmail with my application so that when I receive an email, my application notifies me. Any platform, PHP, Python or Ruby [closed]

$
0
0

I am wondering if I can integrate Gmail or any other email application with my application so that when I receive an email, my application gives me a notification. It can also be like that, when I get notification from the Gmail application, based on that notification, my application also triggers a notification. Thank you very much.

Viewing all 29741 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>